Pimcore\Model\Object\ClassDefinition\Service::skipColumn PHP Method

skipColumn() public static method

public static skipColumn ( $tableDefinitions, $table, $colName, $type, $default, $null ) : boolean
$tableDefinitions
$table
$colName
$type
$default
$null
return boolean
    public static function skipColumn($tableDefinitions, $table, $colName, $type, $default, $null)
    {
        $tableDefinition = $tableDefinitions[$table];
        if ($tableDefinition) {
            $colDefinition = $tableDefinition[$colName];
            if ($colDefinition) {
                if (!strlen($default) && strtolower($null) === "null") {
                    $default = null;
                }
                if ($colDefinition["Type"] == $type && strtolower($colDefinition["Null"]) == strtolower($null) && $colDefinition["Default"] == $default) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * @param $table
  * @param $colName
  * @param $type
  * @param $default
  * @param $null
  */
 protected function addModifyColumn($table, $colName, $type, $default, $null)
 {
     $existingColumns = $this->getValidTableColumns($table, false);
     $existingColName = null;
     // check for existing column case insensitive eg a rename from myInput to myinput
     $matchingExisting = preg_grep('/^' . preg_quote($colName, '/') . '$/i', $existingColumns);
     if (is_array($matchingExisting) && !empty($matchingExisting)) {
         $existingColName = current($matchingExisting);
     }
     if ($existingColName === null) {
         $this->db->query('ALTER TABLE `' . $table . '` ADD COLUMN `' . $colName . '` ' . $type . $default . ' ' . $null . ';');
         $this->resetValidTableColumnsCache($table);
     } else {
         if (!Object\ClassDefinition\Service::skipColumn($this->tableDefinitions, $table, $colName, $type, $default, $null)) {
             $this->db->query('ALTER TABLE `' . $table . '` CHANGE COLUMN `' . $existingColName . '` `' . $colName . '` ' . $type . $default . ' ' . $null . ';');
         }
     }
 }