Пример #1
0
 public static function performDatabaseSchemaUpdate()
 {
     $va_messages = array();
     if (($vn_schema_revision = self::getSchemaVersion()) < __CollectiveAccess_Schema_Rev__) {
         for ($vn_i = $vn_schema_revision + 1; $vn_i <= __CollectiveAccess_Schema_Rev__; $vn_i++) {
             if (!($o_updater = ConfigurationCheck::getVersionUpdateInstance($vn_i))) {
                 $o_updater = new GenericVersionUpdater($vn_i);
             }
             $va_methods_that_errored = array();
             // pre-update tasks
             foreach ($o_updater->getPreupdateTasks() as $vs_preupdate_method) {
                 if (!$o_updater->{$vs_preupdate_method}()) {
                     //$va_messages["error_{$vn_i}_{$vs_preupdate_method}_preupdate"] = _t("Pre-update task '{$vs_preupdate_method}' failed");
                     $va_methods_that_errored[] = $vs_preupdate_method;
                 }
             }
             if (is_array($va_new_messages = $o_updater->applyDatabaseUpdate())) {
                 $va_messages = $va_messages + $va_new_messages;
             } else {
                 $va_messages["error_{$vn_i}_sql_fail"] = _t('Could not apply database update for migration %1', $vn_i);
             }
             // post-update tasks
             foreach ($o_updater->getPostupdateTasks() as $vs_postupdate_method) {
                 if (!$o_updater->{$vs_postupdate_method}()) {
                     //$va_messages["error_{$vn_i}_{$vs_postupdate_method}_postupdate"] = _t("Post-update task '{$vs_postupdate_method}' failed");
                     $va_methods_that_errored[] = $vs_postupdate_method;
                 }
             }
             if ($vs_message = $o_updater->getPostupdateMessage()) {
                 $va_messages[(sizeof($va_methods_that_errored) ? "error" : "info") . "_{$vn_i}_{$vs_postupdate_method}_postupdate_message"] = _t("For migration %1", $vn_i) . ": {$vs_message}";
             } else {
                 if (sizeof($va_methods_that_errored)) {
                     $va_messages["error_{$vn_i}_{$vs_postupdate_method}_postupdate_message"] = _t("For migration %1", $vn_i) . ": " . _t("The following tasks did not complete: %1", join(', ', $va_methods_that_errored));
                 } else {
                     $va_messages["info_{$vn_i}_postupdate"] = _t("Applied migration %1", $vn_i);
                 }
             }
         }
     }
     // Clean cache
     caRemoveDirectory(__CA_APP_DIR__ . '/tmp', false);
     return $va_messages;
 }