Commit 22026c14 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[FEATURE] Add dropbox import

parent d97d5f21
<?php <?php
namespace T3o\T3oMembership\Task; namespace T3o\T3oMembership\Task;
use \TYPO3\CMS\Core\Utility\GeneralUtility; use Dropbox\Dropbox;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
...@@ -25,12 +27,17 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -25,12 +27,17 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
/** /**
* @var string * @var string
*/ */
protected $importFile = ''; public $importFile = '';
/**
* @var string
*/
public $dropboxToken = '';
/** /**
* @var integer * @var integer
*/ */
protected $membershipStoragePid = 0; public $membershipStoragePid = 0;
/** /**
* @var array * @var array
...@@ -64,6 +71,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -64,6 +71,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
if (!file_exists($importFile)) { if (!file_exists($importFile)) {
$logger->debug('No importfile', array('filename' => $importFile)); $logger->debug('No importfile', array('filename' => $importFile));
return false; return false;
} }
...@@ -106,7 +114,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -106,7 +114,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
'hidden' => $hidden, 'hidden' => $hidden,
'starttime' => 0, 'starttime' => 0,
'membership' => $membershipUid, 'membership' => $membershipUid,
'pid' => $this->getMembershipStoragePid(), 'pid' => $this->membershipStoragePid,
'crdate' => time(), 'crdate' => time(),
'tstamp' => time(), 'tstamp' => time(),
'invoice_email' => $fields[84], 'invoice_email' => $fields[84],
...@@ -132,7 +140,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -132,7 +140,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
* Checks if the member with the given subscription number already exists in the database. * Checks if the member with the given subscription number already exists in the database.
* If he exists, his data will be updated, otherwise a new record will be inserted. * If he exists, his data will be updated, otherwise a new record will be inserted.
* *
* @param int $subscriptionNo * @param int $subscriptionNo
* @param array $memberData * @param array $memberData
* @return int The uid of the updated / inserted member. * @return int The uid of the updated / inserted member.
*/ */
...@@ -192,6 +200,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -192,6 +200,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
if (empty($this->memberships[$membershipName])) { if (empty($this->memberships[$membershipName])) {
return null; return null;
} }
return $this->memberships[$membershipName]; return $this->memberships[$membershipName];
} }
...@@ -202,28 +211,12 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -202,28 +211,12 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
*/ */
public function getImportFile() public function getImportFile()
{ {
return $this->importFile; $dropbox = new Dropbox($this->dropboxToken);
} $dropbox->files->download('/TYPO3 Backoffice/Member-Lists/memberlist.txt', $this->importFile);
/** return $this->importFile;
* Sets importFile
*
* @param string $importFile
*/
public function setImportFile($importFile)
{
$this->importFile = $importFile;
} }
/**
* Gets membershipStoragePid
*
* @return int
*/
public function getMembershipStoragePid()
{
return $this->membershipStoragePid;
}
/** /**
* Instantiates all configured hook objects. * Instantiates all configured hook objects.
...@@ -244,16 +237,6 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task ...@@ -244,16 +237,6 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
} }
} }
/**
* Sets membershipStoragePid
*
* @param int $membershipStoragePid
*/
public function setMembershipStoragePid($membershipStoragePid)
{
$this->membershipStoragePid = $membershipStoragePid;
}
/** /**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection * @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/ */
......
...@@ -39,14 +39,14 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A ...@@ -39,14 +39,14 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A
$additionalFields = array(); $additionalFields = array();
// adds field for setting file path for CSV file to import // adds field for setting file path for CSV file to import
$fieldID = 'task_importFile'; $fieldID = 'task_importFile';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[importFile]" id="' . $fieldID . '" value="' . htmlspecialchars($task->importFile) . '" size="30">'; $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[importFile]" id="' . $fieldID . '" value="' . $task->importFile . '" size="120">';
// adds field for setting storage PID // adds field for setting storage PID
$additionalFields[$fieldID] = array( $additionalFields[$fieldID] = array(
'code' => $fieldCode, 'code' => $fieldCode,
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:importFile', 'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:importFile',
); );
$fieldID = 'task_storagePid'; $fieldID = 'task_membershipStoragePid';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[membershipStoragePid]" id="' . $fieldID . '" value="' . (int)$task->membershipStoragePid . '" size="30">'; $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[membershipStoragePid]" id="' . $fieldID . '" value="' . (int)$task->membershipStoragePid . '" size="30">';
// adds field for setting storage PID // adds field for setting storage PID
$additionalFields[$fieldID] = array( $additionalFields[$fieldID] = array(
...@@ -54,6 +54,14 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A ...@@ -54,6 +54,14 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:storagePid' 'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:storagePid'
); );
$fieldID = 'task_dropboxToken';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[dropboxToken]" id="' . $fieldID . '" value="' . $task->dropboxToken . '" size="120">';
// adds field for dropboxToken setting
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:dropboxToken'
);
return $additionalFields; return $additionalFields;
} }
...@@ -82,7 +90,7 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A ...@@ -82,7 +90,7 @@ class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\A
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task){ public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task){
$task->importFile = $submittedData['importFile']; $task->importFile = $submittedData['importFile'];
$task->membershipStoragePid = $submittedData['membershipStoragePid']; $task->membershipStoragePid = $submittedData['membershipStoragePid'];
$task->dropboxToken = $submittedData['dropboxToken'];
} }
} }
t3o membership
==============
What does it do?
----------------
This extension imports our members from dropbox and displays at the
memberlisting at the Assocation page.
Import Settings
---------------
Installation:
* Set up a scheduler task of type membership import
* set up:
* storage pid: Where should the members be imported
* CSV file to import (path and filename): Full path to the location where the memeber file should be stored. The folder should be secured via .htaccess
* Dropbox Token: Token for accessing the dropbox folder
The expected location within dropbox is:
/TYPO3 Backoffice/Member-Lists/memberlist.txt
The file is endocded with: ISO-8859-15
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
<trans-unit id="storagePid"> <trans-unit id="storagePid">
<source>Where to store the member records</source> <source>Where to store the member records</source>
</trans-unit> </trans-unit>
<trans-unit id="dropboxToken">
<source>Dropbox Token</source>
</trans-unit>
<trans-unit id="allMemberships"> <trans-unit id="allMemberships">
<source>All memberships</source> <source>All memberships</source>
</trans-unit> </trans-unit>
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"issues": "https://git-t3o.typo3.org/t3o/t3o_membership/issues" "issues": "https://git-t3o.typo3.org/t3o/t3o_membership/issues"
}, },
"require": { "require": {
"typo3/cms-core": "8.5.0 - 8.9.99" "typo3/cms-core": "8.5.0 - 8.9.99",
"lukebaird/dropbox-v2-php-sdk": "^1.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment