Skip to content

Commit

Permalink
* keep the tstamp from the original records.
Browse files Browse the repository at this point in the history
* support for records without categories
* compatibility TYPO3 9.5: Mostly migrated to query builder
* Add new slots to make a check if an imported and converted record shall really be stored.
  • Loading branch information
franzholz committed Mar 13, 2021
1 parent 49c371e commit 83c7604
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 117 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2021-03-13 Franz Holzinger <[email protected]>

* keep the tstamp from the original records.
* support for records without categories
* compatibility TYPO3 9.5: Mostly migrated to query builder

2020-07-29 Franz Holzinger <[email protected]>

* Add new slots to make a check if an imported and converted record shall really be stored.

2019-12-12 Franz Holzinger <[email protected]>

* Add support for the import into image FAL records referencing to the table sys_file_reference
Expand Down
402 changes: 326 additions & 76 deletions Classes/Api/Api.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Classes/Api/ImportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2019 Franz Holzinger ([email protected])
* (c) 2020 Franz Holzinger ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down
19 changes: 16 additions & 3 deletions Classes/Api/ImportFal.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
*
*/

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;





class ImportFal {
Expand Down Expand Up @@ -73,7 +76,7 @@ public function add (

$sysfileRowArray = array();
$falTable = 'sys_file_reference';
$where_clause = 'uid_foreign=' . intval($row['uid']) . ' AND tablenames=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tablename, $falTable) . ' AND fieldname=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($falFieldname, $falTable);
$where_clause = 'uid_foreign=' . intval($row['uid']) . ' AND tablenames=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tablename, $falTable) . ' AND fieldname=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($falFieldname, $falTable);
$where_clause .= $this->deleteClause('sys_file_reference');

$sysfileRowArray =
Expand Down Expand Up @@ -149,5 +152,15 @@ public function add (
}
}
}

/**
* @param string $tableName
* @return QueryBuilder
*/
public function getQueryBuilder (string $tableName)
{
$result = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
return $result;
}
}

8 changes: 4 additions & 4 deletions Classes/Slots/ExampleFunctionSlots.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class ExampleFunctionSlots implements \TYPO3\CMS\Core\SingletonInterface
{
protected $tables = array('pages', 'tt_content');
protected $tables = ['pages', 'tt_content'];

public function getTables () {
return $this->tables;
Expand All @@ -44,7 +44,7 @@ public function getMenu (
$menuItem = $GLOBALS['LANG']->getLL('menu.' . $table);
$menu[$table] = $menuItem;
}
$result = array($pObj, $menu);
$result = [$pObj, $menu];
return $result;
}

Expand Down Expand Up @@ -88,13 +88,13 @@ public function processImport (
)
{
// TODO: implement the import here
$result = array(
$result = [
$tableName,
$row,
$pid,
$count,
$mode
);
];
return $result;
}
}
Expand Down
85 changes: 85 additions & 0 deletions Classes/Slots/ExampleRecordSlots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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!
*/



/**
* Class for example slots to check and modify records before they get stored
*/
class ExampleRecordSlots implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* Checks the given row of a table during the import if it shall be stored.
*
* @return mixed[] Array with the parameters of the function call
*/
public function checkConvertedRecord (
$tableName,
$row,
$check,
$duplicateCheckNeeded
)
{
// implement the check here
if (
$tableName == 'mytablename' &&
isset($row['name'])
) {
if ($row['name'] == 'unwanted person') {
$check = false;
$duplicateCheckNeeded = false;
} else {
$duplicateCheckNeeded = true;
}
}

$result = [
$tableName,
$row,
$check,
$duplicateCheckNeeded
];
return $result;
}

/**
* modifies the given row of a table during the import
*
* @return mixed[] Array with the parameters of the function call
*/
public function converteRecord (
$tableName,
$row,
$convertedRow
)
{
if (
$tableName == 'mytablename'
) {
$convertedRow = $row;
$convertedRow['imported'] = 1;
}

$result = [
$tableName,
$row,
$convertedRow
];
return $result;
}

}

21 changes: 11 additions & 10 deletions Classes/Slots/ExampleSchedulerSlots.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@
*/
class ExampleSchedulerSlots implements \TYPO3\CMS\Core\SingletonInterface
{
protected $tables = array('pages', 'tt_content');
protected $tables = ['pages', 'tt_content'];

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

$definitionArray[] = $newDefinitionArray;
$result = array($pObj, $definitionArray);
$result = [$pObj, $definitionArray];
return $result;
}
}
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@
"GPL-2.0-or-later"
],
"require": {
"typo3/cms-core": ">=7.6.0,<9.99.99"
"typo3/cms-core": "^8.7, ^9.5"
},
"suggest": {
"typo3/cms-scheduler": "^8.7, ^9.5",
"friendsoftypo3/func": "^9.0",
"friendsoftypo3/typo3db-legacy": "^1.0"
},
"autoload": {
"psr-4": {
"JambageCom\\Import\\": "Classes"
}
},
"replace": {
"jambagecom/import": "self.version",
"typo3-ter/import": "self.version"
"jambagecom/import": "self.version"
},
"extra": {
"typo3/cms": {
Expand Down
7 changes: 3 additions & 4 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
'createDirs' => '',
'clearCacheOnLoad' => 0,
'author_company' => '',
'version' => '0.4.1',
'version' => '0.5.0',
'constraints' => array(
'depends' => array(
'php' => '5.5.0-7.99.99',
'typo3' => '7.6.0-9.99.99',
'typo3' => '8.7.0-9.5.99',
),
'conflicts' => array(
),
'suggests' => array(
'func' => '7.6.0-9.99.99',
'scheduler' => '7.6.0-9.99.99',
'typo3db_legacy' => '1.0.0-1.1.99',
"typo3db_legacy" => ''
),
),
);
Expand Down
49 changes: 33 additions & 16 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
$extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][IMPORT_EXT]);
}

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT])
) {
$tmpArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT];
}

if (isset($extensionConfiguration) && is_array($extensionConfiguration)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] = $extensionConfiguration;
if (isset($tmpArray) && is_array($tmpArray)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] =
array_merge($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT], $tmpArray);
}
} else if (!isset($tmpArray)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] = array();
}

define('IMPORT_CSHKEY', '_MOD_system_txschedulerM1_' . IMPORT_EXT); // key for the Context Sensitive Help

/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
Expand Down Expand Up @@ -62,6 +79,22 @@
'addDefinitionArray' // Slot name
);

$signalSlotDispatcher->connect(
\JambageCom\Import\Api\Api::class,
// Signal class name
'check', // Signal name
\JambageCom\Import\Slots\ExampleRecordSlots::class, // Slot class name
'checkConvertedRecord' // Slot name
);

$signalSlotDispatcher->connect(
\JambageCom\Import\Api\Api::class,
// Signal class name
'convert', // Signal name
\JambageCom\Import\Slots\ExampleRecordSlots::class, // Slot class name
'converteRecord' // Slot name
);

// Add the import task to the scheduler
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\JambageCom\Import\Task\ImportTask::class] = array(
'extension' => IMPORT_EXT,
Expand All @@ -70,22 +103,6 @@
'additionalFields' => \JambageCom\Import\Task\ImportTaskAdditionalFieldProvider::class
);

if (
isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT]) &&
is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT])
) {
$tmpArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT];
}

if (isset($extensionConfiguration) && is_array($extensionConfiguration)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] = $extensionConfiguration;
if (isset($tmpArray) && is_array($tmpArray)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] =
array_merge($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT], $tmpArray);
}
} else if (!isset($tmpArray)) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][IMPORT_EXT] = array();
}
});
}

0 comments on commit 83c7604

Please sign in to comment.