mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
migrate directly from table, not via task object
This commit is contained in:
@@ -61,17 +61,26 @@ class patch_370a7 implements patchInterface
|
||||
public function apply(base &$appbox)
|
||||
{
|
||||
$task_manager = new task_manager($appbox);
|
||||
/* @var $task task_abstract */
|
||||
|
||||
$ttasks = array();
|
||||
$conn = $appbox->get_connection();
|
||||
$sql = 'SELECT task_id, active, name, class, settings FROM task2 WHERE class=\'task_period_workflow01\' OR class=\'task_period_ftv\'';
|
||||
if (($stmt = $conn->prepare($sql)) !== FALSE) {
|
||||
$stmt->execute();
|
||||
$ttasks = $row = $stmt->fetchAll();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
$tdom = array(); // key = period
|
||||
foreach ($task_manager->getTasks() as $task) {
|
||||
$taskstodel = array();
|
||||
foreach ($ttasks as $task) {
|
||||
$active = true;
|
||||
$warning = array();
|
||||
|
||||
/*
|
||||
* migrating task 'workflow01' or 'task_period_ftv'
|
||||
*/
|
||||
if (get_class($task) === 'task_period_workflow01' || get_class($task) === 'task_period_ftv') {
|
||||
$x = $task->getSettings();
|
||||
$x = $task['settings'];
|
||||
if (($sx = simplexml_load_string($x)) !== FALSE) {
|
||||
$period = (int) ($sx->period);
|
||||
|
||||
@@ -92,10 +101,11 @@ class patch_370a7 implements patchInterface
|
||||
/*
|
||||
* migrating task 'workflow01'
|
||||
*/
|
||||
if (get_class($task) === 'task_period_workflow01') {
|
||||
if ($task['class'] === 'task_period_workflow01') {
|
||||
$t = $tasks->appendChild($dom->createElement('task'));
|
||||
$t->setAttribute('active', '0');
|
||||
$t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\'');
|
||||
// $t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\'');
|
||||
$t->setAttribute('name', 'imported from \'' . $task['name'] . '\'');
|
||||
$t->setAttribute('action', 'update');
|
||||
|
||||
if ($sx->sbas_id) {
|
||||
@@ -172,25 +182,28 @@ class patch_370a7 implements patchInterface
|
||||
}
|
||||
}
|
||||
|
||||
if ($active && $task->isActive()) {
|
||||
if ($active && $task['active'] == '1') {
|
||||
$t->setAttribute('active', '1');
|
||||
}
|
||||
foreach ($warning as $w) {
|
||||
$t->appendChild($dom->createComment($w));
|
||||
}
|
||||
|
||||
$taskstodel[] = $task['task_id'];
|
||||
}
|
||||
|
||||
/*
|
||||
* migrating task 'task_period_ftv'
|
||||
*/
|
||||
if (get_class($task) === 'task_period_ftv') {
|
||||
if ($task['class'] === 'task_period_ftv') {
|
||||
foreach ($sx->tasks->task as $sxt) {
|
||||
$active = true;
|
||||
$warning = array();
|
||||
|
||||
$t = $dom->importNode(dom_import_simplexml($sxt), true);
|
||||
$t->setAttribute('active', '0');
|
||||
$t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\'');
|
||||
// $t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\'');
|
||||
$t->setAttribute('name', 'imported from \'' . $task['name'] . '\'');
|
||||
$t->setAttribute('action', 'update');
|
||||
|
||||
if ($sx->sbas_id) {
|
||||
@@ -206,7 +219,7 @@ class patch_370a7 implements patchInterface
|
||||
$active = false;
|
||||
}
|
||||
|
||||
if ($active && $task->isActive()) {
|
||||
if ($active && $task['active'] == '1') {
|
||||
$t->setAttribute('active', '1');
|
||||
}
|
||||
foreach ($warning as $w) {
|
||||
@@ -215,11 +228,9 @@ class patch_370a7 implements patchInterface
|
||||
|
||||
$x = new DOMXPath($dom);
|
||||
$nlfrom = $x->query('from', $t);
|
||||
if($nlfrom->length == 1)
|
||||
{
|
||||
if ($nlfrom->length == 1) {
|
||||
$nlcoll = $x->query('colls', $nlfrom->item(0));
|
||||
if( $nlcoll->length > 0 )
|
||||
{
|
||||
if ($nlcoll->length > 0) {
|
||||
$nn = $dom->createElement('coll');
|
||||
$nn->setAttribute('compare', '=');
|
||||
$nn->setAttribute('id', $nlcoll->item(0)->getAttribute('id'));
|
||||
@@ -229,14 +240,13 @@ class patch_370a7 implements patchInterface
|
||||
$tasks->appendChild($t);
|
||||
}
|
||||
}
|
||||
|
||||
$taskstodel[] = $task['task_id'];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* keep old task for reference but do not start
|
||||
*/
|
||||
// $task->delete();
|
||||
$task->setTitle("TO DELETE : ".$task->getTitle());
|
||||
$task->setActive(false);
|
||||
|
||||
if (count($taskstodel) > 0) {
|
||||
// $conn->exec('DELETE FROM task2 WHERE task_id IN(' . implode(',', $taskstodel) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user