/** *Deletes a configuration entry. * @param $user id * @param $moduleName A non-empty string identifying the module to which * the configuration entry belongs. * @param $key A non-empty string identifying the configuration entry. */ public static function delete($userId, $moduleName, $key) { assert('$userId != null && is_int($userId)'); assert('is_string($moduleName)'); assert('is_string($key)'); assert('$moduleName != ""'); assert('$key != ""'); $bean = UserConfiguration::getBean($userId, $moduleName, $key); if (isset($bean)) { ZurmoRedBean::trash($bean); unset($bean); } }
protected function unrestrictedDelete() { $this->forget(); // RedBeanModel only supports cascaded deletes on associations, // not on links. So for now at least they are done the slow way. foreach (RuntimeUtil::getClassHierarchy(get_class($this), static::$lastClassInBeanHeirarchy) as $modelClassName) { if ($modelClassName::getCanHaveBean()) { $this->deleteOwnedRelatedModels($modelClassName); $this->deleteForeignRelatedModels($modelClassName); $this->deleteManyManyRelations($modelClassName); } } foreach ($this->modelClassNameToBean as $modelClassName => $bean) { ZurmoRedBean::trash($bean); } // The model cannot be used anymore. $this->deleted = true; return true; }
public function save($runValidation = true) { if (!parent::save($runValidation)) { return false; } foreach ($this->deferredRelateBeans as $bean) { if ($this->linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) { if ($this->bean->id == null) { ZurmoRedBean::store($this->bean); } $polyIdFieldName = strtolower($this->linkName) . '_id'; $polyTypeFieldName = strtolower($this->linkName) . '_type'; $bean->{$polyTypeFieldName} = $this->bean->getMeta('type'); $bean->{$polyIdFieldName} = $this->bean->id; } else { ZurmoRedBeanLinkManager::link($bean, $this->bean, $this->resolveLinkNameForCasing()); } ZurmoRedBean::store($bean); } $this->deferredRelateBeans = array(); $relatedModelClassName = $this->relatedModelClassName; $tableName = $relatedModelClassName::getTableName(); foreach ($this->deferredUnrelateBeans as $bean) { if (!$this->owns) { if ($this->linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) { throw new NotSupportedException("Polymorphic relations can not be NOT_OWNED"); } ZurmoRedBeanLinkManager::breakLink($bean, $tableName, $this->resolveLinkNameForCasing()); ZurmoRedBean::store($bean); } else { ZurmoRedBean::trash($bean); } } $this->deferredUnrelatedBeans = array(); foreach ($this->deferredUnrelatedModels as $model) { $event = new CModelEvent($model); $model->onRedBeanOneToManyRelatedModelsChange($event); } $this->deferredUnrelatedModels = array(); return true; }
public function testCascadedDeleteDoesNotWorkForLinkedBeans() { $member = ZurmoRedBean::dispense('marketinglistmember'); $member->unsubscribed = true; ZurmoRedBean::store($member); $list = ZurmoRedBean::dispense('marketinglist'); $list->name = 'dummy'; ZurmoRedBean::store($list); ZurmoRedBeanLinkManager::link($member, $list); ZurmoRedBean::store($member); $id = $list->id; unset($list); ZurmoRedBean::trash($member); unset($member); $list = ZurmoRedBean::load('marketinglist', $id); $this->assertNotNull($list); // The list is not deleted. }