Esempio n. 1
0
 /**
  * Upgrade the MUVideo application from an older version.
  *
  * If the upgrade fails at some point, it returns the last upgraded version.
  *
  * @param integer $oldVersion Version to upgrade from.
  *
  * @return boolean True on success, false otherwise.
  */
 public function upgrade($oldVersion)
 {
     // Upgrade dependent on old version number
     switch ($oldVersion) {
         case '1.0.0':
             // update the database schema
             try {
                 DoctrineHelper::updateSchema($this->entityManager, $this->listEntityClasses());
             } catch (\Exception $e) {
                 if (System::isDevelopmentMode()) {
                     return LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
                 }
                 return LogUtil::registerError($this->__f('An error was encountered while updating tables for the %s extension.', array($this->getName())));
             }
             $categoryRegistryIdsPerEntity = array();
             // add default entry for category registry (property named Main)
             include_once 'modules/MUVideo/lib/MUVideo/Api/Base/Category.php';
             include_once 'modules/MUVideo/lib/MUVideo/Api/Category.php';
             $categoryApi = new MUVideo_Api_Category($this->serviceManager);
             $categoryGlobal = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
             $registryData = array();
             $registryData['modname'] = $this->name;
             $registryData['table'] = 'Collection';
             $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Collection'));
             $registryData['category_id'] = $categoryGlobal['id'];
             $registryData['id'] = false;
             if (!DBUtil::insertObject($registryData, 'categories_registry')) {
                 LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('collection')));
             }
             $categoryRegistryIdsPerEntity['collection'] = $registryData['id'];
             $registryData = array();
             $registryData['modname'] = $this->name;
             $registryData['table'] = 'Movie';
             $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Movie'));
             $registryData['category_id'] = $categoryGlobal['id'];
             $registryData['id'] = false;
             if (!DBUtil::insertObject($registryData, 'categories_registry')) {
                 LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('movie')));
             }
             $categoryRegistryIdsPerEntity['movie'] = $registryData['id'];
             // unregister persistent event handlers
             EventUtil::unregisterPersistentModuleHandlers($this->name);
             // register persistent event handlers
             $this->registerPersistentEventHandlers();
         case '1.1.0':
             // for later updates
     }
     // update successful
     return true;
 }
 /**
  * Upgrade the module from an old version.
  *
  * This function must consider all the released versions of the module!
  * If the upgrade fails at some point, it returns the last upgraded version.
  *
  * @param string $oldversion Version number string to upgrade from.
  *
  * @return  boolean|string True on success, last valid version string or false if fails.
  */
 public function upgrade($oldversion)
 {
     // Upgrade dependent on old version number
     switch ($oldversion) {
         case '3.7.10':
             // Load DB connection
             $connection = $this->entityManager->getConnection();
             // increase length of some hook table fields from 20 to 60
             $commands = array();
             $commands[] = "ALTER TABLE `hook_provider` CHANGE `method` `method` VARCHAR(60) NOT NULL";
             $commands[] = "ALTER TABLE `hook_runtime` CHANGE `method` `method` VARCHAR(60) NOT NULL";
             foreach ($commands as $sql) {
                 $stmt = $connection->executeQuery($sql);
             }
         case '3.7.11':
             \DoctrineHelper::updateSchema($this->entityManager, array('Zikula\\ExtensionsModule\\Entity\\ExtensionEntity'));
         case '3.7.12':
             // future upgrade routines
     }
     // Update successful
     return true;
 }
Esempio n. 3
0
 /**
  * Upgrade the MUBoard application from an older version.
  *
  * If the upgrade fails at some point, it returns the last upgraded version.
  *
  * @param integer $oldversion Version to upgrade from.
  *
  * @return boolean True on success, false otherwise.
  */
 public function upgrade($oldversion)
 {
     // Upgrade dependent on old version number
     switch ($oldversion) {
         case '1.0.0':
             // nothing to do
             // update the database schema
             try {
                 DoctrineHelper::updateSchema($this->entityManager, $this->listEntityClasses());
             } catch (Exception $e) {
                 if (System::isDevelopmentMode()) {
                     LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
                 }
                 return LogUtil::registerError($this->__f('An error was encountered while dropping the tables for the %s module.', array($this->getName())));
             }
             $this->setVar('showStatisticInDetails', true);
             $this->setVar('showStatisticOnBottom', false);
         case '1.1.0':
             // for later updates
     }
     // update successful
     return true;
 }
Esempio n. 4
0
 /**
  * upgrade
  */
 public function upgrade($oldversion)
 {
     // Upgrade dependent on old version number
     switch ($oldversion) {
         case '2.4':
             $prefix = $this->serviceManager['prefix'];
             $connection = Doctrine_Manager::getInstance()->getConnection('default');
             $sql = 'RENAME TABLE ' . $prefix . '_' . 'reviews' . ' TO ' . 'reviews';
             $stmt = $connection->prepare($sql);
             try {
                 $stmt->execute();
             } catch (Exception $e) {
                 LogUtil::registerError($e);
             }
         case '2.4.1':
             try {
                 DoctrineHelper::updateSchema($this->entityManager, $this->listEntityClasses());
             } catch (\Exception $e) {
                 if (System::isDevelopmentMode()) {
                     LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
                 }
                 return LogUtil::registerError($this->__f('An error was encountered while dropping the tables for the %s extension.', array($this->getName())));
             }
             $repository = $this->getEntityManager()->getRepository('Reviews_Entity_Review');
             // we get all old entries
             $result = DBUtil::executeSQL('SELECT * FROM `reviews`');
             $reviews = $result->fetchAll(Doctrine::FETCH_ASSOC);
             $dom = ZLanguage::getModuleDomain($this->name);
             $workflowHelper = new Zikula_Workflow('standard', 'Reviews');
             // we get serviceManager
             $serviceManager = ServiceUtil::getManager();
             // we get entityManager
             $entityManager = $serviceManager->getService('doctrine.entitymanager');
             if (count($reviews) > 0) {
                 foreach ($reviews as $key => $review) {
                     $newReview = new Reviews_Entity_Review();
                     $newReview->setWorkflowState('approved');
                     $newReview->setTitle($review['pn_title']);
                     $newReview->setText($review['pn_text']);
                     if ($review['pn_reviewer'] != '') {
                         $newReview->setReviewer($review['pn_reviewer']);
                     } else {
                         $newReview->setReviewer(__('Unknown', $dom));
                     }
                     if ($review['pn_email'] != '') {
                         $newReview->setEmail($review['pn_email']);
                     } else {
                         $adminmail = UserUtil::getVar('email', 2);
                         $newReview->setEmail(__($adminmail));
                     }
                     $newReview->setScore($review['pn_score']);
                     $newReview->setCover($review['pn_cover']);
                     $newReview->setUrl($review['pn_url']);
                     $newReview->setUrl_title($review['pn_url_title']);
                     $newReview->setHits($review['pn_hits']);
                     $newReview->setZlanguage($review['pn_language']);
                     $createdDate = new Datetime($review['pn_cr_date']);
                     $newReview->setCreatedDate($createdDate);
                     $updatedDate = new DateTime($review['pn_lu_date']);
                     $newReview->setUpdatedDate($updatedDate);
                     $newReview->setCreatedUserId($review['pn_cr_uid']);
                     $newReview->setUpdatedUserId($review['pn_lu_uid']);
                     $entityManager->persist($newReview);
                     $entityManager->flush();
                 }
             }
             $result2 = DBUtil::executeSQL('SELECT * FROM `reviews_review`');
             $reviews2 = $result2->fetchAll(Doctrine::FETCH_ASSOC);
             // we set the workflow
             foreach ($reviews2 as $key => $review2) {
                 $obj['__WORKFLOW__']['obj_table'] = 'review';
                 $obj['__WORKFLOW__']['obj_idcolumn'] = 'id';
                 $obj['id'] = $review2['id'];
                 $workflowHelper->registerWorkflow($obj, 'approved');
             }
             // move relations from categories_mapobj to reviews_category
             // then delete old data
             $connection = $this->entityManager->getConnection();
             $sqls = array();
             $sqls[] = "INSERT INTO reviews_review_category (entityId, registryId, categoryId) SELECT obj_id, reg_id, category_id FROM categories_mapobj WHERE modname = 'Reviews' AND tablename = 'reviews'";
             $sqls[] = "DELETE FROM categories_mapobj WHERE modname = 'Reviews' AND tablename = 'reviews'";
             // update category registry data to change tablename to EntityName
             $sqls[] = "UPDATE categories_registry SET tablename = 'Review' WHERE tablename = 'reviews'";
             // do changes
             foreach ($sqls as $sql) {
                 $stmt = $connection->prepare($sql);
                 try {
                     $stmt->execute();
                 } catch (Exception $e) {
                     LogUtil::registerError($e->getMessage());
                 }
             }
             $pagesize = $this->getVar('itemsperpage');
             $this->setVar('pagesize', $pagesize);
             $this->delVar('itemsperpage');
             $this->setVar('scoreForUsers', false);
             $addcategorytitletopermalink = $this->getVar('addcategorytitletopermalink');
             $this->setVar('addcategorytitletopermalink');
             // register persistent event handlers
             $this->registerPersistentEventHandlers();
             // register hook subscriber bundles
             HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
             DBUtil::dropTable('reviews');
         case '2.5.0':
             // later upgrades
     }
     // upgrade successful
     return true;
 }