/** * Upgrade the dynamic user data module from an old version. * * @param string $oldversion The version from which the upgrade is beginning (the currently installed version); this should be compatible * with {@link version_compare()}. * * @return boolean True on success or false on failure. */ public function upgrade($oldversion) { switch ($oldversion) { case '1.5.2': // 1.5.2 -> 1.6.0 EventUtil::registerPersistentEventHandlerClass($this->name, 'Profile_Listener_UsersUiHandler'); $connection = Doctrine_Manager::getInstance()->getConnection('default'); $sqlStatements = array(); // N.B. statements generated with PHPMyAdmin $sqlStatements[] = 'RENAME TABLE ' . DBUtil::getLimitedTablename('user_property') . " TO user_property"; $sqlStatements[] = "ALTER TABLE `user_property` CHANGE `pn_prop_id` `id` INT( 11 ) NOT NULL AUTO_INCREMENT , CHANGE `pn_prop_label` `label` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , CHANGE `pn_prop_dtype` `dtype` INT( 11 ) NOT NULL DEFAULT '0', CHANGE `pn_prop_modname` `modname` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , CHANGE `pn_prop_weight` `weight` INT( 11 ) NOT NULL DEFAULT '0', CHANGE `pn_prop_validation` `validation` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , CHANGE `pn_prop_attribute_name` `attributename` VARCHAR( 80 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"; foreach ($sqlStatements as $sql) { $stmt = $connection->prepare($sql); try { $stmt->execute(); } catch (Exception $e) { } } case '1.6.0': case '1.6.1': // 1.6.0 -> X.X.X when appropriate. } $modVars = $this->getVars(); $defaultModVars = $this->getDefaultModVars(); // Remove modvars no longer in the default set. foreach ($modVars as $modVar => $value) { if (!array_key_exists($modVar, $defaultModVars)) { $this->delVar($modVar); } } // Add vars defined in the default set, but missing from the current set. foreach ($defaultModVars as $modVar => $value) { if (!array_key_exists($modVar, $modVars)) { $this->setVar($modVar, $value); } } // Update successful return true; }
/** * Upgrade the module from a prior 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 The version number string from which the upgrade starting. * * @return boolean|string True if the module is successfully upgraded to the current version; last valid version string or false if the upgrade fails. */ function upgrade($oldVersion) { // Upgrade dependent on old version number switch ($oldVersion) { case '1.1': // Upgrade 1.1 -> 1.2 $this->setVar('termsofuse', true); $this->setVar('privacypolicy', true); $this->setVar('accessibilitystatement', true); case '1.2': // Upgrade 1.2 -> 1.3 // Nothing to do. case '1.3': // Upgrade 1.3 -> 2.0.0 // Convert the module variables to the new names $this->setVar(Legal_Constant::MODVAR_TERMS_ACTIVE, $this->getVar('termsofuse', true)); $this->delVar('termsofuse'); $this->setVar(Legal_Constant::MODVAR_PRIVACY_ACTIVE, $this->getVar('privacypolicy', true)); $this->delVar('privacypolicy'); $this->setVar(Legal_Constant::MODVAR_ACCESSIBILITY_ACTIVE, $this->getVar('accessibilitystatement', true)); $this->delVar('accessibilitystatement'); // Set the new module variable -- but if Users set it for us during its upgrade, then don't overwrite it $this->setVar(Legal_Constant::MODVAR_MINIMUM_AGE, $this->getVar(Legal_Constant::MODVAR_MINIMUM_AGE, 0)); // Set up the new persistent event handler, and any other event-related features. EventUtil::registerPersistentModuleHandler($this->name, 'user.login.veto', array('Legal_Listener_UsersLoginVeto', 'acceptPoliciesListener')); EventUtil::registerPersistentEventHandlerClass($this->name, 'Legal_Listener_UsersUiHandler'); case '2.0.0': // Upgrade 2.0.0 -> 2.0.1 // add vars for new document types $this->setVar(Legal_Constant::MODVAR_LEGALNOTICE_ACTIVE, false); $this->setVar(Legal_Constant::MODVAR_CANCELLATIONRIGHTPOLICY_ACTIVE, false); $this->setVar(Legal_Constant::MODVAR_TRADECONDITIONS_ACTIVE, false); // add vars for optional custom urls $this->setVar(Legal_Constant::MODVAR_LEGALNOTICE_URL, ''); $this->setVar(Legal_Constant::MODVAR_TERMS_URL, ''); $this->setVar(Legal_Constant::MODVAR_PRIVACY_URL, ''); $this->setVar(Legal_Constant::MODVAR_ACCESSIBILITY_URL, ''); $this->setVar(Legal_Constant::MODVAR_CANCELLATIONRIGHTPOLICY_URL, ''); $this->setVar(Legal_Constant::MODVAR_TRADECONDITIONS_URL, ''); case '2.0.1': // Upgrade 2.0.1 -> ?.?.? // The following break should be the only one in the switch, and should appear immediately prior to the default case. break; default: $this->registerError($this->__f('Upgrading the Legal module from version %1$s to %2$s is not supported.', array($oldVersion, $this->version->getVersion()))); return $oldVersion; } // Update successful return true; }