MetaModels\Helper\TableManipulation::checkColumnDoesNotExist PHP Méthode

checkColumnDoesNotExist() public static méthode

Checks whether the given column does not exist.
public static checkColumnDoesNotExist ( string $strTableName, string $strColName, boolean $blnAllowSystemCol = false ) : void
$strTableName string The table name to check.
$strColName string The column name to check.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
Résultat void
    public static function checkColumnDoesNotExist($strTableName, $strColName, $blnAllowSystemCol = false)
    {
        self::checkTableExists($strTableName);
        self::checkColumnName($strColName, $blnAllowSystemCol);
        if (self::getDB()->fieldExists($strColName, $strTableName, true)) {
            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['columnExists'], $strColName, $strTableName));
        }
    }

Usage Example

Exemple #1
0
 /**
  * Encode the given value from a real language array into a serialized language array.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the column name is illegal or duplicate.
  */
 public function encodeColumnNameValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getProperty() !== 'colname') {
         return;
     }
     $oldColumnName = $event->getModel()->getProperty($event->getProperty());
     $columnName = $event->getValue();
     $metaModel = $this->getMetaModelByModelPid($event->getModel());
     if (!$columnName || $oldColumnName !== $columnName) {
         TableManipulation::checkColumnDoesNotExist($metaModel->getTableName(), $columnName);
         $colNames = array_keys($metaModel->getAttributes());
         if (in_array($columnName, $colNames)) {
             throw new \RuntimeException(sprintf($event->getEnvironment()->getTranslator()->translate('columnExists', 'ERR'), $columnName, $metaModel->getTableName()));
         }
     }
 }