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";
 }
 public function postUp($manager)
 {
     // add the post-migration code here
     $pdo = $manager->getAdapterConnection('rokfor');
     $datasets = TemplatesQuery::create()->find();
     $count = 0;
     foreach ($datasets as $field) {
         $sql = "SELECT * FROM _templates WHERE id = " . $field->getId();
         $stmt = $pdo->prepare($sql);
         $stmt->execute();
         $result = $stmt->fetch(PDO::FETCH_ASSOC);
         echo "Updating template " . $result['_fieldname'] . "\n";
         $_sizes = [];
         $_heights = explode(';', $result['_imageheight']);
         foreach (explode(';', $result['_imagewidth']) as $key => $value) {
             array_push($_sizes, [width => $value, height => $_heights[$key]]);
         }
         $newconfig = array(maxlines => $result['_maxlines'], textlength => $result['_textlength'], imagesize => $_sizes, columns => $result['_cols'], history => $result['_history'] == "ja", growing => $result['_growing'] == "ja");
         $newconfig['lengthinfluence'] = $this->_ConvertInfluenceArray($result['_lengthInfluence']);
         $string = $result['_colNames'];
         switch ($field->getFieldtype()) {
             case 'Text':
                 $newconfig['fullhistory'] = stristr($string, 'fullhistory=true') ? true : false;
                 $newconfig['rtfeditor'] = !stristr($string, 'rtfeditor=false') && !stristr($string, 'codeeditor=true') && !stristr($string, ';');
                 $newconfig['codeeditor'] = stristr($string, 'codeeditor=true') ? true : false;
                 $string = str_ireplace('fullhistory=true', '', $string);
                 $string = str_ireplace('rtfeditor=false', '', $string);
                 $string = str_ireplace('codeeditor=true', '', $string);
                 $_columns = explode(";", $string);
                 $newconfig['editorcolumns'] = [];
                 if (count($_columns) > 1) {
                     $newconfig['arrayeditor'] = true;
                     foreach ($_columns as $_colId => $_colName) {
                         preg_match("/<(.*)>(.*)/", $_colName, $_LengthName);
                         if ($_LengthName[1] == 0) {
                             $_LengthName[1] = 1;
                         }
                         array_push($newconfig['editorcolumns'], ["lines" => $_LengthName[1], "label" => $_LengthName[2]]);
                     }
                 }
                 break;
             case 'Tabelle':
                 $newconfig['colnames'] = explode(';', $string);
                 break;
             default:
                 if (!stristr($string, "=")) {
                     $newconfig['colnames'] = explode(';', $string);
                 } else {
                     $init = parse_ini_string($string, true);
                     if (is_array($init)) {
                         foreach ($init as $type => $row) {
                             if ($type == 'integer') {
                                 $newconfig['integer'] = $row ? true : false;
                             }
                             if ($type == 'resolve_foreign') {
                                 $newconfig['resolve_foreign'] = $row ? true : false;
                             }
                             if ($type == 'multiple') {
                                 $newconfig['multiple'] = $row ? true : false;
                             }
                             if ($type == 'legends') {
                                 $newconfig['legends'] = explode(';', trim($row));
                             }
                             if ($type == 'history') {
                                 $newconfig['history_command'] = $row;
                             }
                             if ($type == 'dateformat') {
                                 $newconfig['dateformat'] = $row;
                             }
                             if ($type == 'fromtemplate') {
                                 $newconfig['fromtemplate'] = $row;
                             }
                             if ($type == 'fromfield') {
                                 $newconfig['fromfield'] = $row;
                             }
                             if ($type == 'frombook') {
                                 $newconfig['frombook'] = $row;
                             }
                             if ($type == 'values') {
                                 $newconfig['fixedvalues'] = explode(';', trim($row));
                             }
                             if ($type == 'restrict_to_open') {
                                 $newconfig['restrict_to_open'] = $row ? true : false;
                             }
                             if ($type == 'restrict_to_issue') {
                                 if ($newconfig['restrict_to_issue'] === "true") {
                                     $newconfig['restrict_to_issue'] = true;
                                 } else {
                                     if ($newconfig['restrict_to_issue'] === "false") {
                                         $newconfig['restrict_to_issue'] = false;
                                     } else {
                                         $newconfig['restrict_to_issue'] = true;
                                         $newconfig['fromissue'] = $row;
                                     }
                                 }
                             }
                             if ($type == 'restrict_to_chapter') {
                                 if ($newconfig['restrict_to_chapter'] === "true") {
                                     $newconfig['restrict_to_chapter'] = true;
                                 } else {
                                     if ($newconfig['restrict_to_chapter'] === "false") {
                                         $newconfig['restrict_to_chapter'] = false;
                                     } else {
                                         $newconfig['restrict_to_chapter'] = true;
                                         $newconfig['fromchapter'] = $row;
                                     }
                                 }
                             }
                             if ($type == 'restrict_to_book') {
                                 if ($newconfig['restrict_to_book'] === "true") {
                                     $newconfig['restrict_to_book'] = true;
                                 } else {
                                     if ($newconfig['restrict_to_book'] === "false") {
                                         $newconfig['restrict_to_book'] = false;
                                     } else {
                                         $newconfig['restrict_to_book'] = true;
                                         $newconfig['frombook'] = $row;
                                     }
                                 }
                             }
                             if ($type == '3d') {
                                 $newconfig['threeDee'] = $row ? true : false;
                             }
                         }
                         if ($newconfig['frombook']) {
                             $newconfig['frombook'] = BooksQuery::create()->filterByName($newconfig['frombook'])->findOne()->getId();
                         }
                         if ($newconfig['fromchapter']) {
                             $newconfig['fromchapter'] = FormatsQuery::create()->filterByName($newconfig['fromchapter'])->findOne()->getId();
                         }
                         if ($newconfig['fromissue']) {
                             $newconfig['fromissue'] = IssuesQuery::create()->filterByName($newconfig['fromissue'])->findOne()->getId();
                         }
                         if ($newconfig['fromtemplate']) {
                             $newconfig['fromtemplate'] = TemplatenamesQuery::create()->filterByName($newconfig['fromtemplate'])->findOne()->getId();
                         }
                         if ($newconfig['fromfield']) {
                             $newconfig['fromfield'] = TemplatesQuery::create()->filterByFieldname($newconfig['fromfield'])->findOne()->getId();
                         }
                         /*                echo "Parsed String\n";
                                         print_r($init);
                                         echo "\n---\n";
                                         print_r($newconfig);
                                         echo "\n---\n";              */
                     }
                 }
                 break;
         }
         $field->setConfigSys(json_encode($newconfig))->save($pdo);
     }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }