Skip to content

Commit

Permalink
* Add example slots
Browse files Browse the repository at this point in the history
* Add scheduler tasks
* Support for TYPO3 9 together with typo3db_legacy
  • Loading branch information
franzholz committed Nov 28, 2019
1 parent 479b9df commit ade1e8c
Show file tree
Hide file tree
Showing 14 changed files with 668 additions and 46 deletions.
14 changes: 13 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
(add new changes on top of this file)
2019-11-28 Franz Holzinger <[email protected]>

* Add example slots
* Add scheduler tasks
* Support for TYPO3 9 together with typo3db_legacy

2019-01-18 Franz Holzinger <[email protected]>

* Make usage of the scheduler

2019-01-18 Franz Holzinger <[email protected]>

* rename Classes/Slots/ExampleSlots.php -> Classes/Slots/ExampleFunctionSlots.php

2017-06-06 Franz Holzinger <[email protected]>

Expand Down
6 changes: 4 additions & 2 deletions Classes/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;


class Api {
/**
Expand All @@ -38,7 +40,7 @@ class Api {
*/
public function __construct ()
{
$this->signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$this->signalSlotDispatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
}

public function importTableFile (
Expand All @@ -48,7 +50,7 @@ public function importTableFile (
$separator = ',',
$enclosure = '"',
$mode = 0,
$firstLineFieldnames = FALSE
$firstLineFieldnames = false
)
{
$result = false;
Expand Down
131 changes: 131 additions & 0 deletions Classes/Api/ImportApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace JambageCom\Import\Api;


/***************************************************************
* Copyright notice
*
* (c) 2019 Franz Holzinger ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Import Api
*
* @author Franz Holzinger <[email protected]>
* @maintainer Franz Holzinger <[email protected]>
* @package TYPO3
* @subpackage import
*/



class ImportApi {

static public function getTableArray () {
$result = array();

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.'])
) {
$systemTableArray = array();
$extensionTableArray = array();

if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['systemtables'] != '') {
$systemTableArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['systemtables']);
}

if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['extensiontables'] != '') {
$extensionTableArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['extensiontables']);
}

$tableArray = array_merge($systemTableArray, $extensionTableArray);
foreach ($tableArray as $table) {
$result[] = array(
'table' => $table,
'title' => $table // TODO: title of the table
);
}
}

return $result;
}

static public function getLocalDefinitionArray () {
$tableArray = self::getTableArray();

$result = array(
array(
'ext' => IMPORT_EXT,
'tables' => $tableArray
)
);
return $result;
}

static public function getPathname () {
$result = false;

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']) &&
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['path'])
) {
$result = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]['import.']['path'];
}

return $result;
}


static public function execute (...$params) {
$result = false;

if (
isset($params) &&
is_array($params) &&
!empty($params)
) {
$result = true;
$tableArray = $params['0'];
foreach ($tableArray as $table) {
if (
isset($GLOBALS['TCA'][$table]) &&
isset($GLOBALS['TCA'][$table]['columns'])
) {
$select_fields = '*';
$where_clause =
$table . '.deleted=0';
// $result = \JambageCom\Move\Api\MoveItemsApi::execute(
// $configurationFile,
// $table,
// $select_fields,
// $where_clause
// );
}
}
}

return $result;
}
}
Empty file.
5 changes: 2 additions & 3 deletions Classes/Slots/ExampleSlots.php → Classes/Slots/ExampleFunctionSlots.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use JambageCom\Import\Api\Api;

/**
* Class for example slots to import files into TYPO3 tables
* Class for example slots to import files into TYPO3 tables based on the Function Module
*/
class ExampleSlots implements \TYPO3\CMS\Core\SingletonInterface
class ExampleFunctionSlots implements \TYPO3\CMS\Core\SingletonInterface
{
protected $tables = array('pages', 'tt_content');

Expand Down Expand Up @@ -98,4 +98,3 @@ public function processImport (
}
}


55 changes: 55 additions & 0 deletions Classes/Slots/ExampleSchedulerSlots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace JambageCom\Import\Slots;

/*
* 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!
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;

use JambageCom\Import\Api\Api;

/**
* Class for example slots to import files into TYPO3 tables based on the Scheduler Module
*/
class ExampleSchedulerSlots implements \TYPO3\CMS\Core\SingletonInterface
{
protected $tables = array('pages', 'tt_content');

public function addDefinitionArray(
$pObj,
array $definitionArray
)
{
$newDefinitionArray =
array(
'ext' => IMPORT_EXT,
'class' => null,
'tables' => array(
array(
'table' => 'pages',
'title' => 'Pages'
),
array(
'table' => 'fe_users',
'title' => 'Front End Users'
),
)
);

$definitionArray[] = $newDefinitionArray;
$result = array($pObj, $definitionArray);
return $result;
}
}


146 changes: 146 additions & 0 deletions Classes/Task/ImportTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

namespace JambageCom\Import\Task;

/***************************************************************
* Copyright notice
*
* (c) 2019 Franz Holzinger ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Import Task
*
* @author Franz Holzinger <[email protected]>
* @maintainer Franz Holzinger <[email protected]>
* @package TYPO3
* @subpackage import
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;

class ImportTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {

/**
* Array of tables to import
*
* @var array $tableArray
*/
public $tableArray;

/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected $signalSlotDispatcher;

/**
* Constructor
*/
public function __construct()
{
parent::__construct();

$this->signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
}

public function execute ()
{
$result = false;
$slotDefinitionArray = array();
$slotResult =
$this->signalSlotDispatcher->dispatch(
__CLASS__,
'definition',
array(
$this,
$slotDefinitionArray
)
);
$slotDefinitionArray = $slotResult['1'];

if (
isset($this->tableArray) &&
is_array($this->tableArray) &&
!empty($this->tableArray)
) {
$result = true;
$localDefinitionArray = \JambageCom\Import\Api\ImportApi::getLocalDefinitionArray();
$definitionArray = array_merge($localDefinitionArray, $slotDefinitionArray);
//
foreach ($definitionArray as $definition) {
if (
!isset($definition['tables']) ||
!is_array($definition['tables'])
) {
continue;
}

if (isset($definition['ext'])) {

$foreignExtension = $definition['ext'];
if (
$foreignExtension != IMPORT_EXT &&
!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($foreignExtension)
) {
return false;
}
}

$extensionTables = array();
foreach ($definition['tables'] as $tableDefinition) {
$extensionTables[] = $tableDefinition['table'];
}
$theTableArray = array();

foreach ($this->tableArray as $table) {
if (in_array($table, $extensionTables)) {
$theTableArray[] = $table;
}
}

if (!empty($theTableArray)) {
if (isset($definition['class'])) {

$foreignClass = $definition['class'];
if (
class_exists($foreignClass) &&
method_exists($foreignClass, 'execute')
) {
$foreignObject = GeneralUtility::makeInstance($foreignClass);
$result = $foreignObject->execute($theTableArray);
} else {
$result = false;
break;
}
} else {
\JambageCom\Import\Api\ImportApi::execute($theTableArray);
}
}
}
}

return $result;
}


public function getAdditionalInformation ()
{
}
}
Loading

0 comments on commit ade1e8c

Please sign in to comment.