Skip to content

Commit

Permalink
[BUGFIX] Also migrate local processing of template objects
Browse files Browse the repository at this point in the history
Related: #44
  • Loading branch information
Alexander Opitz committed Apr 4, 2017
1 parent 6998f29 commit f405533
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 26 deletions.
88 changes: 73 additions & 15 deletions Classes/Controller/Update/DataStructureUpdateHandler.php
Expand Up @@ -18,6 +18,7 @@
use TYPO3\CMS\Core\Utility\StringUtility;

use Ppi\TemplaVoilaPlus\Domain\Repository\DataStructureRepository;
use Ppi\TemplaVoilaPlus\Domain\Repository\TemplateRepository;

/**
* Handles Updates in DataStructure via Callbacks
Expand All @@ -40,28 +41,60 @@ public function updateAllDs(array $rootCallbacks, array $elementCallbacks)
return $count;
}

public function updateAllToLocals(array $rootCallbacks, array $elementCallbacks)
{
$count = 0;

$tsRepo = GeneralUtility::makeInstance(TemplateRepository::class);
foreach ($tsRepo->getAll() as $to) {
if ($this->updateTo($to, $rootCallbacks, $elementCallbacks)) {
$count++;
}
}

return $count;
}

public function updateDs(
\Ppi\TemplaVoilaPlus\Domain\Model\AbstractDataStructure $ds,
array $rootCallbacks,
array $elementCallbacks
) {
$changed = false;
$data = $ds->getDataprotArray();
$this->lastKey = $ds->getKey();

foreach ($rootCallbacks as $callback) {
if (is_callable($callback)) {
$changed = $callback($data) || $changed;
}
}
$changed = $this->processUpdate($data, $rootCallbacks, $elementCallbacks);

foreach($data['ROOT']['el'] as &$element) {
$changed = $this->fixPerElement($element, $elementCallbacks) || $changed;
if ($changed) {
$this->saveChange(
$ds->getKey(),
'tx_templavoilaplus_datastructure',
'dataprot',
GeneralUtility::array2xml_cs(
$data,
'T3DataStructure',
['useCDATA' => 1]
),
$ds->isFilebased()
);
return true;
}
return false;
}

public function updateTo(
\Ppi\TemplaVoilaPlus\Domain\Model\Template $to,
array $rootCallbacks,
array $elementCallbacks
) {
$data = $to->getLocalDataprotArray(true);

$changed = $this->processUpdate($data, $rootCallbacks, $elementCallbacks);

if ($changed) {
$this->saveChange(
$ds,
$to->getKey(),
'tx_templavoilaplus_tmplobj',
'localprocessing',
GeneralUtility::array2xml_cs(
$data,
'T3DataStructure',
Expand All @@ -73,20 +106,45 @@ public function updateDs(
return false;
}

protected function saveChange($ds, $dataProtXML)

public function processUpdate(
array &$data,
array $rootCallbacks,
array $elementCallbacks
) {
$changed = false;

if (empty($data)) {
return false;
}

foreach ($rootCallbacks as $callback) {
if (is_callable($callback)) {
$changed = $callback($data) || $changed;
}
}

foreach($data['ROOT']['el'] as &$element) {
$changed = $this->fixPerElement($element, $elementCallbacks) || $changed;
}

return $changed;
}

protected function saveChange($key, $table, $field, $dataProtXML, $filebased = false)
{
if ($ds->isFilebased()) {
$path = PATH_site . $ds->getKey();
if ($filebased) {
$path = PATH_site . $key;
GeneralUtility::writeFile($path, $dataProtXML);
} else {
$tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tce->stripslashes_values = 0;

$dataArr = [];
$dataArr['tx_templavoilaplus_datastructure'][$ds->getKey()]['dataprot'] = $dataProtXML;
$dataArr[$table][$key][$field] = $dataProtXML;

// process data
$tce->start($dataArr, array());
$tce->start($dataArr, []);
$tce->process_datamap();
}
}
Expand Down
19 changes: 19 additions & 0 deletions Classes/Controller/Update/OldTemplavoilaUpdateController.php
Expand Up @@ -95,6 +95,9 @@ protected function stepFinal()
if (($migratedDsData = $this->migrateDataStructureData()) === false) {
$this->errors[] = 'Error while migrate data of data structures.';
}
if (($migratedToData = $this->migrateTemplateObjectLocalProcessing()) === false) {
$this->errors[] = 'Error while migrate local processing data of template objects.';
}
if (($migratedUploadFiles = $this->migrateFiles()) === false) {
$this->errors[] = 'Error while copy files from uploads/tx_templavoila to uploads/tx_templavoilaplus.';
}
Expand All @@ -112,6 +115,7 @@ protected function stepFinal()
'migrateGroupTableModify' => $migrateGroupTableModify,
'migrateGroupNonExcludeFields' => $migrateGroupNonExcludeFields,
'migratedDsData' => $migratedDsData,
'migratedToData' => $migratedToData,
'migratedUploadFiles' => $migratedUploadFiles,
'errors' => $this->errors,
]);
Expand Down Expand Up @@ -372,6 +376,21 @@ private function migrateDataStructureData()
);
}

// Convert DS <T3DataStructure><ROOT><tx_templavoila>
// Convert DS <T3DataStructure><ROOT><el><field..><tx_templavoila>
private function migrateTemplateObjectLocalProcessing()
{
$handler = GeneralUtility::makeInstance(DataStructureUpdateHandler::class);
return $handler->updateAllToLocals(
[
[$this, 'migrateRootData'],
],
[
[$this, 'migrateElementData'],
]
);
}

public function migrateRootData(&$data)
{
if (isset($data['ROOT']['tx_templavoila'])) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Template.php
Expand Up @@ -378,7 +378,7 @@ public function getLocalDataprotArray($skipDsDataprot = false)
if (!$skipDsDataprot) {
$dataprot = $this->getDatastructure()->getDataprotArray();
} else {
$dataprot = array();
$dataprot = [];
}
$toDataprot = GeneralUtility::xml2array($this->row['localprocessing']);

Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/TemplateRepository.php
Expand Up @@ -115,7 +115,7 @@ public function getTemplatesByParentTemplate(\Ppi\TemplaVoilaPlus\Domain\Model\T
}

/**
* Retrieve a collection (array) of tx_templavoilaplus_datastructure objects
* Retrieve a collection (array) of tx_templavoilaplus_tmplobj objects
*
* @param integer $storagePid
*
Expand All @@ -141,7 +141,7 @@ public function getAll($storagePid = 0)
}

/**
* Sorts datastructure alphabetically
* Sorts templates alphabetically
*
* @param \Ppi\TemplaVoilaPlus\Domain\Model\Template $obj1
* @param \Ppi\TemplaVoilaPlus\Domain\Model\Template $obj2
Expand Down
Expand Up @@ -4,7 +4,7 @@
.t3js-module-body h1:first-child {display: none;}
</style>

<h1>TemplaVoilà Plus! Migration from old TeamplaVoilà 1.9/2.0</h1>
<h1>TemplaVoilà Plus! Migration from old TeamplaVoilà 1.8/1.9/2.0</h1>
<f:be.infobox title="Information" state="-1">Migration done.</f:be.infobox>
<f:be.infobox title="Migrated" state="0">
<p>Migrated Configuration</p>
Expand All @@ -20,6 +20,7 @@ <h1>TemplaVoilà Plus! Migration from old TeamplaVoilà 1.9/2.0</h1>
<p>Migrated group table modify: {migrateGroupTableModify}</p>
<p>Migrated group non exclude fields: {migrateGroupNonExcludeFields}</p>
<p>Migrated Data Structures data: {migratedDsData}</p>
<p>Migrated Template Objects local processing: {migratedToData}</p>
<p>Migrated Upload Files: {migratedUploadFiles}</p>
</f:be.infobox>

Expand Down
Expand Up @@ -4,7 +4,7 @@
.t3js-module-body h1:first-child {display: none;}
</style>

<h1>TemplaVoilà Plus! Update from old TeamplaVoilà 1.9/2.0</h1>
<h1>TemplaVoilà Plus! Update from old TeamplaVoilà 1.8/1.9/2.0</h1>
<f:be.infobox title="Warning" state="1">
Please backup your database/files before running any of the update scripts!<br />
This will remove data you already did with this new TemplaVoilà Plus 7.x Extension.
Expand All @@ -18,7 +18,7 @@ <h1>TemplaVoilà Plus! Update from old TeamplaVoilà 1.9/2.0</h1>
</f:for>
</f:then>
<f:else>
<h2>Migrate from TemplaVoilà 1.9/2.0 to TemplaVoilà Plus 7.x?</h2>
<h2>Migrate from TemplaVoilà 1.8/1.9/2.0 to TemplaVoilà Plus 7.x?</h2>
<form action="#" method="POST">
<input type="hidden" name="update" value="OldTemplavoila" />
<p>We will migrate from old TeamplaVoilà {old.ds} / {old.to} Data Structures/Template Objects (in database) over the already existing {new.ds} / {new.to} Data Structures/Template Objects which are in new TemplaVoilà Plus 7.x (in database).</p>
Expand All @@ -28,7 +28,7 @@ <h2>Migrate from TemplaVoilà 1.9/2.0 to TemplaVoilà Plus 7.x?</h2>
<p><b>This will remove data you already did with this new TemplaVoilà Plus 7.x Extension.</b></p>
<f:be.infobox title="" state="1">
<button class="btn btn-warning btn-block btn-lg" type="submit" name="step" value="final">
<core:icon identifier="extensions-scheduler-run-task" /> Yes, migrate data from TemplaVoilà 1.9/2.0 to TemplaVoilà Plus 7.x
<core:icon identifier="extensions-scheduler-run-task" /> Yes, migrate data from TemplaVoilà 1.8/1.9/2.0 to TemplaVoilà Plus 7.x
</button>
</div>
</f:be.infobox>
Expand Down
8 changes: 4 additions & 4 deletions Resources/Private/Templates/Update/Switch.html
Expand Up @@ -8,17 +8,17 @@ <h1>TemplaVoilà Plus! Update Script Selection</h1>
<f:be.infobox title="Warning" state="1">Please backup your data before running any of the update scripts!</f:be.infobox>
<h2>Please select an update script</h2>
<form action="#" method="POST">
<f:be.infobox title="Migrate from the old TemplaVoilà (1.9/2.0) Extension" state="-1">
<f:be.infobox title="Migrate from the old TemplaVoilà (1.8/1.9/2.0) Extension" state="-1">
<button class="btn btn-primary btn-block btn-lg" type="submit" name="update" value="OldTemplavoila">
<core:icon identifier="extensions-scheduler-run-task" /> Migrate TemplaVoilà 1.9/2.0
<core:icon identifier="extensions-scheduler-run-task" /> Migrate TemplaVoilà 1.8/1.9/2.0
</button>
</f:be.infobox>
<f:be.infobox title="You should run this, to fix the TYPO3 TCA Changes between 6.2 and 7/8 LTS" state="-1">
<button class="btn btn-primary btn-block btn-lg" type="submit" name="update" value="DataStructure">
<core:icon identifier="extensions-scheduler-run-task" /> Update DataStructure
<core:icon identifier="extensions-scheduler-run-task" /> Update DataStructure from TYPO3 6.2 to 7/8 LTS
</button>
</f:be.infobox>
<f:be.infobox title="Static Data Structure will be the way to gut. But it may be need some love/tests yet." state="1">
<f:be.infobox title="Static Data Structure will be the way to go. But it may be need some love/tests yet." state="1">
<button class="btn btn-warning btn-block btn-lg" type="submit" name="update" value="StaticData">
<core:icon identifier="extensions-scheduler-run-task" /> Convert to Static Data Structure
</button>
Expand Down

0 comments on commit f405533

Please sign in to comment.