/** * Handle the update of a render setting. * * This resets the default flags for all other render settings when becoming the default. * * @param PostPersistModelEvent $event The event. * * @return void */ public function handleUpdate(PostPersistModelEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_rendersettings') { return; } $new = $event->getModel(); if (!$new->getProperty('isdefault')) { return; } $this->getDatabase()->prepare('UPDATE tl_metamodel_rendersettings SET isdefault = \'\' WHERE pid=? AND id<>? AND isdefault=1')->execute($new->getProperty('pid'), $new->getId()); }
/** * Retrieve the arguments for the callback. * * @param PostPersistModelEvent $event The event being emitted. * * @return array */ public function getArgs($event) { return array(new DcCompat($event->getEnvironment())); }
/** * Handle the update of an attribute and all attached data. * * @param PostPersistModelEvent $event The event. * * @return void */ public function handleUpdateAttribute(PostPersistModelEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute') { return; } $old = $event->getOriginalModel(); $new = $event->getModel(); $oldInstance = $old->getProperty('pid') ? $this->createAttributeInstance($old->getPropertiesAsArray()) : null; $newInstance = $this->createAttributeInstance($new->getPropertiesAsArray()); // If type or column name has been changed, destroy old data and initialize new. if (self::isAttributeNameOrTypeChanged($event)) { // Destroy old instance. if ($oldInstance) { $oldInstance->destroyAUX(); } // Create new instance aux info. if ($newInstance) { $newInstance->initializeAUX(); } } if ($newInstance) { // Now loop over all values and update the meta in the instance. foreach ($new->getPropertiesAsArray() as $strKey => $varValue) { $newInstance->handleMetaChange($strKey, $varValue); } } }
/** * Handle the update of a MetaModel and all attached data. * * @param PostPersistModelEvent $event The event. * * @return void */ public function handleUpdate(PostPersistModelEvent $event) { if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') { return; } $old = $event->getOriginalModel(); $new = $event->getModel(); $oldTable = $old ? $old->getProperty('tableName') : null; $newTable = $new->getProperty('tableName'); // Table name changed? if ($oldTable !== $newTable) { if ($oldTable && $this->getDatabase()->tableExists($oldTable, null, true)) { TableManipulation::renameTable($oldTable, $newTable); // TODO: notify attributes that the MetaModel has changed its table name. } else { TableManipulation::createTable($newTable); } } TableManipulation::setVariantSupport($newTable, $new->getProperty('varsupport')); }