protected function dropColumn() { $restore = $this->getRestoreFileName(); if (Sabel_Db_Migration_Manager::isUpgrade()) { if (is_file($restore)) { unlink($restore); } $columns = $this->getReader()->readDropColumn()->getColumns(); $schema = $this->getSchema()->getTable($this->tblName); $sColumns = $schema->getColumns(); $writer = new Sabel_Db_Migration_Writer($restore); $writer->writeColumns($schema, $columns); $writer->close(); foreach ($columns as $column) { if (isset($sColumns[$column])) { unset($sColumns[$column]); } else { $warning = "column '{$column}' does not exist. (SKIP)"; Sabel_Console::warning($warning); } } $this->dropColumnsAndRemakeTable($sColumns, $schema); } else { $columns = $this->getReader($restore)->readAddColumn()->getColumns(); $this->execAddColumn($columns); } }
public function create($dir = null) { if ($dir === null) { $dir = $this->skeletonDir . DS . self::DEFAULT_LANGUAGE; } foreach (scandir($dir) as $item) { if ($item[0] === "." && $item !== ".htaccess") { continue; } $fullPath = $dir . DS . $item; $targetItem = substr($fullPath, $this->basedirNameLength + 1); $targetPath = $this->targetDir . DS . $targetItem; if (is_dir($fullPath)) { if (isset($this->ignore[$targetItem])) { Sabel_Console::message("ignore '{$targetItem}'."); } else { if (is_dir($targetPath)) { Sabel_Console::warning("'{$targetItem}' already exists."); } else { Sabel_Console::success("create {$targetItem}"); mkdir($targetPath); } $this->create($fullPath); } } else { if ($this->lang !== self::DEFAULT_LANGUAGE) { $_target = substr($fullPath, strlen($this->skeletonDir) + 4); // DS(1) + lang(2) + DS(1) $_target = $this->skeletonDir . DS . $this->lang . DS . $_target; if (is_dir($_target) || is_file($_target)) { $fullPath = $_target; } } if (isset($this->ignore[$targetItem])) { Sabel_Console::message("ignore '{$targetItem}'."); } elseif (is_file($targetPath)) { Sabel_Console::warning("'{$targetItem}' already exists."); } else { Sabel_Console::success("create {$targetItem}"); copy($fullPath, $targetPath); } } } }
public function testMessage() { $_SERVER["IS_WINDOWS"] = true; ob_start(); Sabel_Console::success("success"); $result = ob_get_clean(); $this->assertEquals("[SUCCESS] success", rtrim($result)); ob_start(); Sabel_Console::warning("warning"); $result = ob_get_clean(); $this->assertEquals("[WARNING] warning", rtrim($result)); ob_start(); Sabel_Console::error("failure"); $result = ob_get_clean(); $this->assertEquals("[FAILURE] failure", rtrim($result)); ob_start(); Sabel_Console::message("message"); $result = ob_get_clean(); $this->assertEquals("[MESSAGE] message", rtrim($result)); }
protected function create() { $tblName = convert_to_tablename($this->mdlName); $schema = $this->getSchema(); $tables = $schema->getTableList(); if (Sabel_Db_Migration_Manager::isUpgrade()) { if (in_array($tblName, $tables)) { Sabel_Console::warning("table '{$tblName}' already exists. (SKIP)"); } else { $this->createTable($this->filePath); } } else { if (in_array($tblName, $tables)) { $this->dropSequence($schema->getTable($tblName)->getSequenceColumn()); $this->executeQuery("DROP TABLE " . $this->quoteIdentifier($tblName)); } else { Sabel_Console::warning("unknown table '{$tblName}'. (SKIP)"); } } }
public function warning($msg) { echo Sabel_Console::warning($msg); }
protected function alterChange($column, $current) { $line = array(); $line[] = $column->name; if ($current->isText() && $column->type !== null && !$column->isText()) { Sabel_Console::warning("cannot modify lob column '{$current->name}'. (SKIP)"); } elseif (!$current->isText()) { $col = $column->type === null ? $current : $column; $type = $this->getTypeDefinition($col, false); if ($col->isString()) { $max = $column->max === null ? $current->max : $column->max; $line[] = $type . "({$max})"; } else { $line[] = $type; } } if (($d = $column->default) === _NULL) { $line[] = "DEFAULT NULL"; } else { $cd = $current->default; if ($d === $cd) { $line[] = $this->getDefaultValue($current); } else { $this->valueCheck($column, $d); $line[] = $this->getDefaultValue($column); } } if ($current->nullable === true && $column->nullable === false) { $line[] = "NOT NULL"; } elseif ($current->nullable === false && $column->nullable === true) { $line[] = "NULL"; } return implode(" ", $line); }
protected function dropColumn() { $restore = $this->getRestoreFileName(); if (Sabel_Db_Migration_Manager::isUpgrade()) { if (is_file($restore)) { unlink($restore); } $columns = $this->getReader()->readDropColumn()->getColumns(); $schema = $this->getSchema()->getTable($this->tblName); $colNames = $schema->getColumnNames(); $writer = new Sabel_Db_Migration_Writer($restore); $writer->writeColumns($schema, $columns)->close(); $quotedTblName = $this->quoteIdentifier($this->tblName); foreach ($columns as $column) { if (in_array($column, $colNames)) { $colName = $this->quoteIdentifier($column); $this->executeQuery("ALTER TABLE {$quotedTblName} DROP COLUMN {$colName}"); } else { Sabel_Console::warning("column '{$column}' does not exist. (SKIP)"); } } } else { $columns = $this->getReader($restore)->readAddColumn()->getColumns(); $this->execAddColumn($columns); } }