public function postUp($manager) { $pdo = $manager->getAdapterConnection('rokfor'); // populate relative fields: _issues foreach (array('_singleplugin', '_allplugin', '_rtfplugin', '_xmlplugin', '_narrationplugin') as $_field) { $datasets = IssuesQuery::create()->find(); $count = 0; foreach ($datasets as $issue) { $sql = "SELECT " . $_field . " FROM _issues WHERE id = " . $issue->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach ($this->_splitTextListData($result[$_field]) as $key) { $p = PluginsQuery::create()->findPk($key); if ($p) { echo "Add Plugin with id " . $key . " from " . $_field . "\n"; switch ($_field) { case '_singleplugin': $issue->addSinglePlugin($p); break; case '_allplugin': $issue->addAllPlugin($p); break; case '_rtfplugin': $issue->addRtfPlugin($p); break; case '_xmlplugin': $issue->addXmlPlugin($p); break; case '_narrationplugin': $issue->addNarrationPlugin($p); break; } } } $issue->save($pdo); } } $datasets = RightsQuery::create()->find(); $count = 0; foreach ($datasets as $right) { $sql = "SELECT * FROM _rights WHERE id = " . $right->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach (array('_fortemplate', '_forissue', '_forbook', '_foruser') as $_field) { foreach ($this->_splitTextListData($result[$_field]) as $key) { if ($key) { switch ($_field) { case '_fortemplate': $p = TemplatenamesQuery::create()->findPk($key); if ($p) { $right->addTemplatenames($p); } break; case '_forissue': $p = IssuesQuery::create()->findPk($key); if ($p) { $right->addIssues($p); } break; case '_forbook': $p = BooksQuery::create()->findPk($key); if ($p) { $right->addBooks($p); } break; case '_foruser': $p = UsersQuery::create()->findPk($key); if ($p) { $right->addUsers($p); } break; } } } } $right->save($pdo); } $datasets = BatchQuery::create()->find(); $count = 0; foreach ($datasets as $batch) { $sql = "SELECT * FROM _batch WHERE id = " . $batch->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach (array('_forbook') as $_field) { foreach ($this->_splitTextListData($result[$_field]) as $key) { if ($key) { switch ($_field) { case '_forbook': $p = BooksQuery::create()->findPk($key); if ($p) { $batch->addBooks($p); } break; } } } } $batch->save($pdo); } $datasets = FieldpostprocessorQuery::create()->find(); $count = 0; foreach ($datasets as $proc) { $sql = "SELECT * FROM _fieldpostprocessor WHERE id = " . $proc->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach (array('_forfield') as $_field) { foreach ($this->_splitTextListData($result[$_field]) as $key) { if ($key) { switch ($_field) { case '_forfield': $p = TemplatesQuery::create()->findPk($key); if ($p) { $proc->addTemplates($p); } break; } } } } $proc->save($pdo); } $datasets = TemplatenamesQuery::create()->find(); $count = 0; foreach ($datasets as $template) { $sql = "SELECT * FROM _templatenames WHERE id = " . $template->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach (array('_inchapter', '_forbook') as $_field) { foreach ($this->_splitTextListData($result[$_field]) as $key) { if ($key) { switch ($_field) { case '_inchapter': $p = FormatsQuery::create()->findPk($key); if ($p) { $template->addFormats($p); } break; case '_forbook': $p = BooksQuery::create()->findPk($key); if ($p) { $template->addBooks($p); } break; } } } } $template->save($pdo); } // migrate data into new content field, set json to true if it is jsonized. $datasets = DataQuery::create()->find(); $count = 0; echo "\n"; echo "Updating " . count($datasets) . " Fields: "; foreach ($datasets as $data) { echo "."; $count++; $_parsed_text = ""; $_is_json = false; $sql = "SELECT * FROM _data WHERE id = " . $data->getId(); $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); switch ($data->getTemplates()->getFieldtype()) { case 'Bild': $_parsed_text = $this->_splitTableData($result['_databinary']); $_is_json = true; break; case 'Tabelle': $_parsed_text = $this->_splitTableData($result['_datatext']); $_is_json = true; break; case 'TypologyCloud': $_parsed_text = $this->_splitCloudData($this->_splitTableData($result['_datatext'])); $_is_json = true; break; case 'MetaMatrix': $_parsed_text = json_decode($_parsed_text); $_is_json = true; break; case 'TargetMatrix': case 'TimeMatrix': $_parsed_text = $this->_splitTextListData($result['_datatext']); $_parsed_text[1] = json_decode($_parsed_text[1]); $_is_json = true; break; case 'Zahl': case 'TypologySlider': $_parsed_text = $result['_datainteger']; break; case 'TypologyKeyword': $_parsed_text = $this->_splitWordListData($result['_datatext']); $_is_json = true; break; default: if (stristr($result['_datatext'], '<::::::>')) { $_parsed_text = $this->_splitTextListData($result['_datatext']); $_is_json = true; } else { if (stristr($result['_datatext'], '<;;;;;;>')) { $_parsed_text = $this->_splitWordListData($result['_datatext']); $_is_json = true; } else { $_parsed_text = $result['_datatext']; } } break; } $data->setContent($_is_json ? json_encode($_parsed_text) : $_parsed_text); $data->setIsjson($_is_json); $data->save($pdo); } echo "\nDone\n"; }
/** * creates history values for reference fields * * @return void * @author Urs Hofer */ function getHistory() { $thisfield = $this->getTemplates(); $contribution = $this->getContributions(); $settings = json_decode($thisfield->getConfigSys(), true); $retval = []; if ($settings['fromfield']) { $field = \TemplatesQuery::create()->findPk($settings['fromfield']); } else { $field = $thisfield; } if ($settings['fromtemplate']) { $template = \TemplatenamesQuery::create()->findPk($settings['fromtemplate']); } else { $template = $thisfield->getTemplatenames(); } if ($settings['fromissue']) { $issue = \IssuesQuery::create()->findPk($settings['fromissue']); } else { $issue = $contribution->getIssues(); } if ($settings['frombook']) { $book = \BooksQuery::create()->findPk($settings['frombook']); } else { $book = $contribution->getIssues()->getBooks(); } if ($settings['fromchapter']) { $chapter = \FormatsQuery::create()->findPk($settings['fromchapter']); } else { $chapter = $contribution->getFormats(); } if (!$chapter || !$book || !$issue || !$template || !$field) { array_push($retval, ["id" => -1, "value" => "Error - adjust template settings"]); } else { switch ($settings['history_command']) { // // BOOK HISTORY // needs : - // option : - // Returns books // case 'books': foreach (\BooksQuery::create() as $_b) { array_push($retval, ["id" => $_b->getId(), "value" => $_b->getName()]); } break; // // ISSUES HISTORY // option : frombook(string), otherwise self // option : restrict_to_open(bool) // Returns issues of a book // // // ISSUES HISTORY // option : frombook(string), otherwise self // option : restrict_to_open(bool) // Returns issues of a book // case 'issues': $issues = \IssuesQuery::create()->_if($settings['restrict_to_book'])->filterByBooks($book)->_endif()->_if($settings['restrict_to_open'])->filterByStatus('open')->_endif(); foreach ($issues as $_b) { array_push($retval, ["id" => $_b->getId(), "value" => $_b->getName()]); } break; // // CHAPTERS HISTORY // option : frombook(string), otherwise self // Returns chapters of a book // // // CHAPTERS HISTORY // option : frombook(string), otherwise self // Returns chapters of a book // case 'chapters': $formats = \FormatsQuery::create()->_if($settings['restrict_to_book'])->filterByBooks($book)->_endif(); foreach ($formats as $_b) { array_push($retval, ["id" => $_b->getId(), "value" => $_b->getName()]); } break; // // CLOUD HISTORY // TODO // Returns cloud matrix data for a field. // // // CLOUD HISTORY // TODO // Returns cloud matrix data for a field. // case 'cloud': array_push($retval, ["id" => -1, "value" => "not yet implemented"]); // // OTHER HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: fromfield (necessary for other history) // Returns chapters of a book // // // OTHER HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: fromfield (necessary for other history) // Returns chapters of a book // case 'other': $_data = \DataQuery::create()->filterByTemplates($field)->_if($settings['restrict_to_issue'])->useContributionsQuery()->filterByIssues($issue)->endUse()->_endif()->useContributionsQuery()->_if($settings['restrict_to_open'])->filterByStatus('Open')->_else()->filterByStatus('Open')->_or()->filterByStatus('Close')->_endif()->endUse(); foreach ($_data as $_b) { array_push($retval, ["id" => $_b->getId(), "value" => $_b->getContent()]); } break; // // SELF HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: fromfield (necessary for other history) // Returns chapters of a book // // // SELF HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: fromfield (necessary for other history) // Returns chapters of a book // case 'self': $_data = \DataQuery::create()->filterByTemplates($field)->_if($settings['restrict_to_issue'])->useContributionsQuery()->filterByIssues($issue)->endUse()->_endif()->useContributionsQuery()->_if($settings['restrict_to_open'])->filterByStatus('Open')->_else()->filterByStatus('Open')->_or()->filterByStatus('Close')->_endif()->endUse(); foreach ($_data as $_b) { foreach (json_decode($_b->getContent(), true) as $_d) { $retval[$_d] = ["id" => $_d, "value" => $_d]; } } ksort($retval); break; // // CONTRIBUTIONS HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: restrict_to_chapter(bool): true = fromchapter or self / false = all chapters // option: fromtemplate(string), otherwise self // Returns contributions of a issue // // // CONTRIBUTIONS HISTORY // option: restrict_to_issue(bool): true = fromissue or self / false = all issues // option: restrict_to_open(bool): true = open contributions / false = all contributions // option: restrict_to_chapter(bool): true = fromchapter or self / false = all chapters // option: fromtemplate(string), otherwise self // Returns contributions of a issue // case 'contributional': $_data = \ContributionsQuery::create()->_if($settings['restrict_to_issue'])->filterByIssues($issue)->_endif()->_if($settings['restrict_to_open'])->filterByStatus('Open')->_else()->filterByStatus('Open')->_or()->filterByStatus('Close')->_endif()->_if($settings['restrict_to_chapter'])->filterByFormats($chapter)->_endif()->_if($settings['restrict_to_template'])->filterByTemplatenames($template)->_endif(); foreach ($_data as $_b) { array_push($retval, ["id" => $_b->getId(), "value" => $_b->getName()]); } break; // // STRUCTURAL HISTORY // option: fromtemplate(string), otherwise fields of own template // Returns fields of a template // // // STRUCTURAL HISTORY // option: fromtemplate(string), otherwise fields of own template // Returns fields of a template // case 'structural': foreach (\TemplatesQuery::create()->filterByTemplatenames($template) as $_t) { array_push($retval, ["id" => $_t->getId(), "value" => $_t->getFieldname()]); } # code... break; // // FIXED HISTORY // needs : fixedvalues(array of strings) // option : - // Returns fixed string values // // // FIXED HISTORY // needs : fixedvalues(array of strings) // option : - // Returns fixed string values // case 'fixed': foreach ($settings['fixedvalues'] as $key => $value) { array_push($retval, ["id" => $key, "value" => $value]); } break; } // Always add a disabled state array_push($retval, ["id" => -1, "value" => "* Disabled *"]); } return $retval; }