Commit 70459335 authored by Thomas Löffler's avatar Thomas Löffler

Merge branch '13-import-from-dropbox' into 'master'

Resolve "Import from dropbox"

Closes #13

See merge request !4
parents f89da165 22026c14
<?php
namespace T3o\T3oMembership\Task;
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Class Tx_T3oMembership_Task_ImportMembersAdditionalFields
*
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class ImportMembersAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
{
/**
* Gets additional fields to render in the form to add/edit a task
*
* @param array $taskInfo
* @param Task $task
* @param SchedulerModuleController $schedulerModule
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '',
* 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
*/
public function getAdditionalFields(array &$taskInfo, Task $task, SchedulerModuleController $schedulerModule)
{
$additionalFields = array();
// adds field for setting file path for CSV file to import
$importFile = '';
$membershipStoragePid = 0;
if ($task instanceof Task) {
$importFile = htmlspecialchars($task->getImportFile());
$membershipStoragePid = (int)$task->getMembershipStoragePid();
}
$additionalFields['importFile'] = array(
'code' => '<input type="text" name="tx_scheduler[importFile]" value="' . $importFile . '" />',
'label' => LocalizationUtility::translate('importFile', 't3omembership')
);
// adds field for setting storage PID
$additionalFields['storagePid'] = array(
'code' => '<input type="text" name="tx_scheduler[storagePid]" value="' . $membershipStoragePid . '" />',
'label' => LocalizationUtility::translate('storagePid', 't3omembership')
);
return $additionalFields;
}
/**
* Validates the additional fields' values
*
* @param array $submittedData
* @param SchedulerModuleController $schedulerModule
* @return boolean
*/
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
// only validation for importFile would be a file_exists, but it will be validated in the task itself
return true;
}
/**
* Takes care of saving the additional fields' values in the task's object
*
* @param array $submittedData
* @param Task $task
* @return void
*/
public function saveAdditionalFields(array $submittedData, Task $task)
{
$task->setImportFile($submittedData['importFile']);
$task->setMembershipStoragePid($submittedData['storagePid']);
}
}
\ No newline at end of file
<?php
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.
......@@ -25,12 +27,17 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
/**
* @var string
*/
protected $importFile = '';
public $importFile = '';
/**
* @var string
*/
public $dropboxToken = '';
/**
* @var integer
*/
protected $membershipStoragePid = 0;
public $membershipStoragePid = 0;
/**
* @var array
......@@ -64,6 +71,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
if (!file_exists($importFile)) {
$logger->debug('No importfile', array('filename' => $importFile));
return false;
}
......@@ -106,7 +114,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
'hidden' => $hidden,
'starttime' => 0,
'membership' => $membershipUid,
'pid' => $this->getMembershipStoragePid(),
'pid' => $this->membershipStoragePid,
'crdate' => time(),
'tstamp' => time(),
'invoice_email' => $fields[84],
......@@ -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.
* If he exists, his data will be updated, otherwise a new record will be inserted.
*
* @param int $subscriptionNo
* @param int $subscriptionNo
* @param array $memberData
* @return int The uid of the updated / inserted member.
*/
......@@ -192,6 +200,7 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
if (empty($this->memberships[$membershipName])) {
return null;
}
return $this->memberships[$membershipName];
}
......@@ -202,28 +211,12 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
*/
public function getImportFile()
{
return $this->importFile;
}
$dropbox = new Dropbox($this->dropboxToken);
$dropbox->files->download('/TYPO3 Backoffice/Member-Lists/memberlist.txt', $this->importFile);
/**
* Sets importFile
*
* @param string $importFile
*/
public function setImportFile($importFile)
{
$this->importFile = $importFile;
return $this->importFile;
}
/**
* Gets membershipStoragePid
*
* @return int
*/
public function getMembershipStoragePid()
{
return $this->membershipStoragePid;
}
/**
* Instantiates all configured hook objects.
......@@ -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
*/
......
<?php
namespace T3o\T3oMembership\Task;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Class ImportMembersTaskAdditionalFieldProvider
*
* @author Thomas Löffler <thomas.loeffler@typo3.org>
*/
class ImportMembersTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
{
/**
* Gets additional fields to render in the form to add/edit a task
*
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
* @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
*/
public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
{
$additionalFields = array();
// adds field for setting file path for CSV file to import
$fieldID = 'task_importFile';
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[importFile]" id="' . $fieldID . '" value="' . $task->importFile . '" size="120">';
// adds field for setting storage PID
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'label' => 'LLL:EXT:t3o_membership/Resources/Private/Language/locallang.xlf:importFile',
);
$fieldID = 'task_membershipStoragePid';
$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
$additionalFields[$fieldID] = array(
'code' => $fieldCode,
'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;
}
/**
* This method checks any additional data that is relevant to the specific task
* If the task class is not relevant, the method is expected to return TRUE
*
* @param array $submittedData Reference to the array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
{
// only validation for importFile would be a file_exists, but it will be validated in the task itself
return true;
}
/**
* This method is used to save any additional input into the current task object
* if the task class matches
*
* @param array $submittedData Array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
*/
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task){
$task->importFile = $submittedData['importFile'];
$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
......@@ -50,14 +50,17 @@
<source>Search</source>
</trans-unit>
<trans-unit id="importFile">
<source>CSV file to import</source>
<source>CSV file to import (path and filename)</source>
</trans-unit>
<trans-unit id="storagePid">
<source>Where to store the member records</source>
</trans-unit>
<trans-unit id="dropboxToken">
<source>Dropbox Token</source>
</trans-unit>
<trans-unit id="allMemberships">
<source>All memberships</source>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
</xliff>
......@@ -9,7 +9,8 @@
"issues": "https://git-t3o.typo3.org/t3o/t3o_membership/issues"
},
"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": {
"psr-4": {
......
<?php
$extensionClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('t3o_membership', 'Classes/');
// ?
return array(
'tx_t3omembership_task_importmemberstask' => $extensionClassesPath . 'Task/ImportMembersTask.php',
'tx_t3omembership_task_importmembers_additionalfieldprovider' => $extensionClassesPath . 'Task/ImportMembersAdditionalFieldProvider.php'
);
......@@ -22,5 +22,5 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\T3oMembersh
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xlf:tx_t3omembership_task_importmemberstask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xlf:tx_t3omembership_task_importmemberstask.description',
'additionalFields' => 'tx_t3omembership_task_importmembers_additionalfieldprovider',
'additionalFields' => \T3o\T3oMembership\Task\ImportMembersTaskAdditionalFieldProvider::class
);
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