Beispiel #1
0
 function alterTable($tablename, $newdatadef, $info, $aggressive = false)
 {
     $dd = $this->getDataDefinition($tablename);
     $modified = false;
     if ($aggressive) {
         $oldcols = array_diff_assoc($dd, $newdatadef);
         if (count($oldcols)) {
             $modified = true;
             $sql = "ALTER TABLE `" . $this->prefix . "{$tablename}` ";
             foreach ($oldcols as $name => $def) {
                 $sql .= " DROP COLUMN " . $name . ",";
             }
             $sql = substr($sql, 0, -1);
             @mysql_query($sql, $this->connection);
         }
     }
     $diff = array_diff_assoc($newdatadef, $dd);
     if (count($diff)) {
         $modified = true;
         $sql = "ALTER TABLE `" . $this->prefix . "{$tablename}` ";
         foreach ($diff as $name => $def) {
             $sql .= " ADD COLUMN (" . $this->fieldSQL($name, $def) . "),";
         }
         $sql = substr($sql, 0, -1);
         @mysql_query($sql, $this->connection);
     }
     $return = array($tablename => $modified ? TABLE_ALTER_SUCCEEDED : TABLE_ALTER_NOT_NEEDED);
     if (isset($info[DB_TABLE_WORKFLOW]) && $info[DB_TABLE_WORKFLOW]) {
         // Initialize workflow tables:
         if (!defined("SYS_WORKFLOW")) {
             require_once BASE . "subsystems/workflow.php";
         }
         $wf = pathos_workflow_alterWorkflowTables($tablename, $newdatadef, $aggressive);
         foreach ($wf as $key => $status) {
             $return[$key] = $status;
         }
     }
     return $return;
 }
Beispiel #2
0
 function alterTable($tablename, $newdatadef, $info, $aggressive = false)
 {
     $dd = $this->getDataDefinition($tablename);
     $modified = false;
     if ($aggressive) {
         $oldcols = array_diff_assoc($dd, $newdatadef);
         if (count($oldcols)) {
             $modified = true;
             foreach ($oldcols as $name => $def) {
                 $sql = "ALTER TABLE " . $this->prefix . $tablename . ' DROP COLUMN "' . $name . '"';
                 pg_query($this->connection, $sql);
             }
         }
     }
     $diff = array_diff_assoc($newdatadef, $dd);
     if (count($diff)) {
         $modified = true;
         foreach ($diff as $name => $def) {
             $sql = 'ALTER TABLE "' . $this->prefix . $tablename . '" ADD COLUMN ' . $this->fieldSQL($name, $def);
             #echo $sql .'<br />';
             pg_query($this->connection, $sql);
         }
     }
     if (isset($info[DB_TABLE_WORKFLOW]) && $info[DB_TABLE_WORKFLOW]) {
         // Initialize workflow tables:
         if (!defined("SYS_WORKFLOW")) {
             require_once BASE . "subsystems/workflow.php";
         }
         pathos_workflow_alterWorkflowTables($tablename, $newdatadef);
     }
     if ($modified) {
         return TABLE_ALTER_SUCCEEDED;
     } else {
         return TABLE_ALTER_NOT_NEEDED;
     }
 }
Beispiel #3
0
function pathos_workflow_installWorkflowTables($existingname, $tabledef)
{
    return pathos_workflow_alterWorkflowTables($existingname, $tabledef);
}