コード例 #1
0
 /**
  * Checks for and applies schema upgrades for the module
  *
  */
 function update()
 {
     // list files in a directory
     $files = owa_lib::listDir(OWA_DIR . 'modules' . '/' . $this->name . '/' . 'updates', false);
     //print_r($files);
     $current_schema_version = $this->c->get($this->name, 'schema_version');
     // extract sequence
     foreach ($files as $k => $v) {
         // the use of %d casts the sequence number as an int which is critical for maintaining the
         // order of the keys in the array that we are going ot create that holds the update objs
         //$n = sscanf($v['name'], '%d_%s', $seq, $classname);
         $seq = substr($v['name'], 0, -4);
         settype($seq, "integer");
         if ($seq > $current_schema_version) {
             if ($seq <= $this->required_schema_version) {
                 $this->updates[$seq] = owa_coreAPI::updateFactory($this->name, substr($v['name'], 0, -4));
                 // if the cli update mode is required and we are not running via cli then return an error.
                 owa_coreAPI::debug('cli update mode required: ' . $this->updates[$seq]->isCliModeRequired());
                 if ($this->updates[$seq]->isCliModeRequired() === true && !defined('OWA_CLI')) {
                     //set flag in module
                     $this->update_from_cli_required = true;
                     owa_coreAPI::notice("Aborting update {$seq}. This update must be applied using the command line interface.");
                     return false;
                 }
                 // set schema version from sequence number in file name. This ensures that only one update
                 // class can ever be in use for a particular schema version
                 $this->updates[$seq]->schema_version = $seq;
             }
         }
     }
     // sort the array
     ksort($this->updates, SORT_NUMERIC);
     //print_r(array_keys($this->updates));
     foreach ($this->updates as $k => $obj) {
         $this->e->notice(sprintf("Applying Update %d (%s)", $k, get_class($obj)));
         $ret = $obj->apply();
         if ($ret == true) {
             $this->e->notice("Update Suceeded");
         } else {
             $this->e->notice("Update Failed");
             return false;
         }
     }
     return true;
 }
コード例 #2
0
 function rollback($update)
 {
     list($module, $seq) = explode('.', $update);
     $u = owa_coreAPI::updateFactory($module, $seq);
     $u->rollback();
     owa_coreAPI::notice("Rollback completed.");
 }