function update081() { $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED); $dirname = $this->_mCurrentXoopsModule->get('dirname'); $root = XCube_Root::getSingleton(); $db = $root->mController->getDB(); $handler = Legacy_Utils::getModuleHandler('definition', $dirname); $revisionHandler = Legacy_Utils::getModuleHandler('revision', $dirname); $pageHandler = Legacy_Utils::getModuleHandler('page', $dirname); //prepare revision table $sql = "DESC `" . $db->prefix($dirname . '_revision') . "` "; if (!($result = $db->query($sql))) { $this->mLog->addReport($db->error()); } while ($row = $db->fetchArray($result)) { $revisionFields[] = $row['Field']; } $definitions = $handler->getObjects(); foreach ($definitions as $definition) { $fieldType = $definition->get('field_type'); if (!in_array($definition->get('field_name'), $revisionFields)) { $fieldType = $definition->getFieldType(); $sql = 'ALTER TABLE %s ADD `' . $definition->get('field_name') . '` ' . $fieldType->getTableQuery($definition->get('field_type')); $db->query(sprintf($sql, $db->prefix($dirname . '_revision'))); } } //copy revision data from page if ($revisionHandler->getCount(new Criteria('1', '1')) == 0) { $pageObjs = $pageHandler->getObjects(); foreach ($pageObjs as $page) { $revision = Xcck_Utils::setupRevisionByPage($page); if (!$revisionHandler->insert($revision, true)) { $this->mLog->addReport($db->error()); } } } $this->_mCurrentVersion = $this->_mTargetVersion; return $this->executeAutomaticUpgrade(); }
public function insert(&$obj, $force = false) { $ret = true; if ($obj->isNew() || $obj->get('status') === Lenum_Status::PUBLISHED) { $ret = parent::insert($obj, $force); } if ($ret === false) { return false; } //update revision $revision = Xcck_Utils::setupRevisionByPage($obj); $handler = Legacy_Utils::getModuleHandler('revision', $this->getDirname()); $ret = $handler->insert($revision, $force); return $ret; }