forked from reinhardfuehricht/typo3-formhandler
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added update script for migrating list_type plugin to CType
This was apparently changed with formhandler 2.1
- Loading branch information
Andreas Kiessling
committed
Nov 10, 2016
1 parent
f6084b0
commit 235535f
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
namespace Typoheads\Formhandler; | ||
|
||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
|
||
class ext_update | ||
{ | ||
public function main() | ||
{ | ||
$pluginsToMigrate = $this->countListTypePlugins(); | ||
if ($pluginsToMigrate > 0) { | ||
$this->migrateListTypePlugins(); | ||
} | ||
$remainingPluginsToMigrate = $this->countListTypePlugins(); | ||
if ($remainingPluginsToMigrate === 0) { | ||
return "Success: Migrated $pluginsToMigrate formhandler plugins from list_type to CType. The forms should now show up again in the frontend."; | ||
} else { | ||
return "Error: $pluginsToMigrate formhandler plugins should have been migrated, but $remainingPluginsToMigrate are still left."; | ||
} | ||
} | ||
|
||
/** | ||
* Activate update script if any pre 2.1 plugins are in the database | ||
* | ||
* @return bool | ||
*/ | ||
public function access() | ||
{ | ||
return $this->countListTypePlugins() > 0; | ||
} | ||
|
||
private function countListTypePlugins() | ||
{ | ||
return $this->getDb()->exec_SELECTcountRows( | ||
'*', | ||
'tt_content', | ||
'CType = \'list\' AND list_type = \'formhandler_pi1\'' . BackendUtility::deleteClause('tt_content') | ||
); | ||
} | ||
|
||
private function migrateListTypePlugins() | ||
{ | ||
$this->getDb()->exec_UPDATEquery( | ||
'tt_content', | ||
'CType = \'list\' AND list_type = \'formhandler_pi1\'' . BackendUtility::deleteClause('tt_content'), | ||
[ | ||
'CType' => 'formhandler_pi1' | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @return \TYPO3\CMS\Core\Database\DatabaseConnection | ||
*/ | ||
private function getDb() | ||
{ | ||
return $GLOBALS['TYPO3_DB']; | ||
} | ||
} |