MetaModels\Helper\TableManipulation::checkTableDoesNotExist PHP Метод

checkTableDoesNotExist() публичный статический Метод

Ensures that the given table does not exist.
public static checkTableDoesNotExist ( string $strTableName ) : void
$strTableName string The table name to check.
Результат void
    public static function checkTableDoesNotExist($strTableName)
    {
        self::checkTablename($strTableName);
        if (self::getDB()->tableExists($strTableName, null, true)) {
            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['tableExists'], $strTableName));
        }
    }

Usage Example

Пример #1
0
 /**
  * Called by tl_metamodel.tableName onsave_callback.
  *
  * Prefixes the table name with mm_ if not provided by the user as such.
  * Checks if the table name is legal to the DB.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When no table name has been given.
  */
 public function ensureTableNamePrefix(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel' || $event->getProperty() !== 'tableName') {
         return;
     }
     // See #49.
     $tableName = strtolower($event->getValue());
     if (!strlen($tableName)) {
         throw new \RuntimeException('Table name not given');
     }
     // Force mm_ prefix.
     if (substr($tableName, 0, 3) !== 'mm_') {
         $tableName = 'mm_' . $tableName;
     }
     $dataProvider = $event->getEnvironment()->getDataProvider('tl_metamodel');
     // New model, ensure the table does not exist.
     if (!$event->getModel()->getId()) {
         TableManipulation::checkTableDoesNotExist($tableName);
     } else {
         // Edited model, ensure the value is unique and then that the table does not exist.
         $oldVersion = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($event->getModel()->getId()));
         if ($oldVersion->getProperty('tableName') !== $event->getModel()->getProperty('tableName')) {
             TableManipulation::checkTableDoesNotExist($tableName);
         }
     }
     $event->setValue($tableName);
 }