Skip to content

Commit

Permalink
[FEATURE] Refactor Importer class, resolves #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Suter committed Jun 16, 2017
1 parent 383b71a commit 75083a0
Show file tree
Hide file tree
Showing 34 changed files with 2,850 additions and 1,587 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2017-06-16 Francois Suter (Cobweb) <[email protected]>

* Refactored Importer class, resolves #8

2017-03-23 Francois Suter (Cobweb) <[email protected]>

* Corrected logic of "useColumnIndex" validator, resolves #3
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/DataModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function synchronizeAction($table, $index)
{
// Synchronize the chosen data
/** @var Importer $importer */
$importer = GeneralUtility::makeInstance(Importer::class);
$importer = $this->objectManager->get(Importer::class);
$messages = $importer->synchronizeData($table, $index);

// Perform reporting
Expand Down
4 changes: 2 additions & 2 deletions Classes/DataHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface DataHandlerInterface
* Handles the raw data passed to it and returns it as a simple, indexed PHP array
*
* @param mixed $rawData Data to handle. Could be of any type, as suited for the data handler.
* @param Importer $importerObject The calling importer object
* @param Importer $importer Back-reference to the current Importer instance
* @return array The handled data, as PHP array
*/
public function handleData($rawData, Importer $importerObject);
public function handleData($rawData, Importer $importer);
}
211 changes: 211 additions & 0 deletions Classes/Domain/Model/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php
namespace Cobweb\ExternalImport\Domain\Model;

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

/**
* Pseudo-domain model for a single External Import configuration.
*
* @package Cobweb\ExternalImport\Domain\Model
*/
class Configuration
{
/**
* @var string Name of the table to which the configuration applies
*/
protected $table;

/**
* @var int|string Index identifying the configuration for the given table
*/
protected $index;

/**
* @var array "ctrl" part of the External Import configuration
*/
protected $ctrlConfiguration;

/**
* @var array External Import configuration for each column
*/
protected $columnConfiguration;

/**
* @var array List of fields that must be read from distant stored, but will not be stored to DB
*/
protected $additionalFields = array();

/**
* @var int Number of additional fields (cached to avoid counting too often)
*/
protected $countAdditionalFields = 0;

/**
* @var \Cobweb\Svconnector\Service\ConnectorBase Reference to the connector object
*/
protected $connector;

/**
* @return string
*/
public function getTable()
{
return $this->table;
}

/**
* @param string $table
*/
public function setTable($table)
{
$this->table = $table;
}

/**
* @return int|string
*/
public function getIndex()
{
return $this->index;
}

/**
* @param int|string $index
*/
public function setIndex($index)
{
$this->index = $index;
}

/**
* @return array
*/
public function getCtrlConfiguration()
{
return $this->ctrlConfiguration;
}

/**
* @param array $ctrlConfiguration
*/
public function setCtrlConfiguration(array $ctrlConfiguration)
{
$this->ctrlConfiguration = $ctrlConfiguration;
if (array_key_exists('additionalFields', $ctrlConfiguration)) {
$additionalFields = GeneralUtility::trimExplode(
',',
$ctrlConfiguration['additionalFields'],
true
);
$this->setAdditionalFields($additionalFields);
$this->setCountAdditionalFields(
count($additionalFields)
);
}
}

/**
* Returns a specific property from the "ctrl" configuration.
*
* @param $key
* @return mixed|null
*/
public function getCtrlConfigurationProperty($key)
{
if (array_key_exists($key, $this->ctrlConfiguration)) {
return $this->ctrlConfiguration[$key];
}
return null;
}

/**
* @return array
*/
public function getColumnConfiguration()
{
return $this->columnConfiguration;
}

/**
* @param array $columnConfiguration
*/
public function setColumnConfiguration(array $columnConfiguration)
{
$this->columnConfiguration = $columnConfiguration;
}

/**
* Returns the External import configuration for a single column.
*
* @param string $column Name of the column
* @return array
*/
public function getConfigurationForColumn($column)
{
if (array_key_exists($column, $this->columnConfiguration)) {
return $this->columnConfiguration[$column];
}
return array();
}

/**
* @return array
*/
public function getAdditionalFields()
{
return $this->additionalFields;
}

/**
* @param array $additionalFields
*/
public function setAdditionalFields(array $additionalFields)
{
$this->additionalFields = $additionalFields;
}

/**
* @return int
*/
public function getCountAdditionalFields()
{
return $this->countAdditionalFields;
}

/**
* @param int $countAdditionalFields
*/
public function setCountAdditionalFields($countAdditionalFields)
{
$this->countAdditionalFields = $countAdditionalFields;
}

/**
* @return \Cobweb\Svconnector\Service\ConnectorBase
*/
public function getConnector()
{
return $this->connector;
}

/**
* @param \Cobweb\Svconnector\Service\ConnectorBase $connector
*/
public function setConnector(\Cobweb\Svconnector\Service\ConnectorBase $connector)
{
$this->connector = $connector;
}
}
65 changes: 65 additions & 0 deletions Classes/Domain/Model/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace Cobweb\ExternalImport\Domain\Model;

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

/**
* Pseudo-domain model for the data being handled by the import process.
*
* @package Cobweb\ExternalImport\Domain\Model
*/
class Data
{
/**
* @var mixed The data to import, before it has been processed in any way
*/
protected $rawData;

/**
* @var array Array of data being imported
*/
protected $records = array();

/**
* @return mixed
*/
public function getRawData()
{
return $this->rawData;
}

/**
* @param mixed $rawData
*/
public function setRawData($rawData)
{
$this->rawData = $rawData;
}

/**
* @return array
*/
public function getRecords()
{
return $this->records;
}

/**
* @param array $records
*/
public function setRecords(array $records)
{
$this->records = $records;
}
}
Loading

0 comments on commit 75083a0

Please sign in to comment.