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 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) {
                 R::store($this->bean);
             }
             $polyIdFieldName = strtolower($this->linkName) . '_id';
             $polyTypeFieldName = strtolower($this->linkName) . '_type';
             $bean->{$polyTypeFieldName} = $this->bean->getMeta('type');
             $bean->{$polyIdFieldName} = $this->bean->id;
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = RedBeanModel::getTableName($this->modelClassName);
                 RedBeanColumnTypeOptimizer::optimize($tableName, $polyIdFieldName, 'id');
             }
         } else {
             ZurmoRedBeanLinkManager::link($bean, $this->bean, $this->resolveLinkNameForCasing());
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = RedBeanModel::getTableName($this->modelClassName);
                 $columnName = RedBeanModel::getTableName($this->relatedModelClassName) . '_id';
                 $columnName = ZurmoRedBeanLinkManager::resolveColumnPrefix($this->resolveLinkNameForCasing()) . $columnName;
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
         R::store($bean);
     }
     $this->deferredRelateBeans = array();
     $tableName = RedBeanModel::getTableName($this->relatedModelClassName);
     foreach ($this->deferredUnrelateBeans as $bean) {
         if (!$this->owns) {
             ZurmoRedBeanLinkManager::breakLink($bean, $tableName, $this->resolveLinkNameForCasing());
             R::store($bean);
         } else {
             R::trash($bean);
         }
     }
     $this->deferredUnrelateBeans = array();
     return true;
 }
Exemplo n.º 3
0
 protected function linkBeans()
 {
     $baseModelClassName = null;
     $baseBean = null;
     foreach ($this->modelClassNameToBean as $modelClassName => $bean) {
         if ($baseBean !== null) {
             ZurmoRedBeanLinkManager::link($bean, $baseBean);
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = self::getTableName($modelClassName);
                 $columnName = self::getTableName($baseModelClassName) . '_id';
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
         $baseModelClassName = $modelClassName;
         $baseBean = $bean;
     }
 }
Exemplo n.º 4
0
 protected function linkBeans()
 {
     // Link the beans up the inheritance hierarchy, skipping
     // the person bean, then link that to the user. So the
     // user is linked to both the person and the permitable,
     // to complete the mixing in of the Person's data.
     $baseBean = null;
     foreach ($this->modelClassNameToBean as $modelClassName => $bean) {
         if ($modelClassName == 'Person') {
             continue;
         }
         if ($baseBean !== null) {
             ZurmoRedBeanLinkManager::link($bean, $baseBean);
         }
         $baseBean = $bean;
     }
     $userBean = $this->modelClassNameToBean['User'];
     $personBean = $this->modelClassNameToBean['Person'];
     ZurmoRedBeanLinkManager::link($userBean, $personBean);
 }
Exemplo n.º 5
0
 protected function linkBeans()
 {
     // Link the beans up the inheritance hierarchy, skipping
     // the person bean, then link that to the user. So the
     // user is linked to both the person and the permitable,
     // to complete the mixing in of the Person's data.
     $baseBean = null;
     foreach ($this->modelClassNameToBean as $modelClassName => $bean) {
         if ($modelClassName == 'Person') {
             continue;
         }
         if ($baseBean !== null) {
             ZurmoRedBeanLinkManager::link($bean, $baseBean);
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = self::getTableName(get_class($this));
                 $columnName = 'person_id';
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
         $baseBean = $bean;
     }
     $userBean = $this->modelClassNameToBean['User'];
     $personBean = $this->modelClassNameToBean['Person'];
     ZurmoRedBeanLinkManager::link($userBean, $personBean);
     if (!RedBeanDatabase::isFrozen()) {
         $tableName = self::getTableName(get_class($this));
         RedBeanColumnTypeOptimizer::optimize($tableName, 'person_id', 'id');
     }
 }
Exemplo n.º 6
0
 protected function linkBeans()
 {
     $baseBean = null;
     foreach ($this->modelClassNameToBean as $modelClassName => $bean) {
         if ($baseBean !== null) {
             ZurmoRedBeanLinkManager::link($bean, $baseBean);
         }
         $baseBean = $bean;
     }
 }
Exemplo n.º 7
0
 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.
 }
Exemplo n.º 8
0
 public function testCascadedDeleteDoesNotWorkForLinkedBeans()
 {
     $person = R::dispense('person');
     $person->name = 'bill';
     R::store($person);
     $phone = R::dispense('phone');
     $phone->number = '555-1234';
     R::store($phone);
     ZurmoRedBeanLinkManager::link($phone, $person);
     R::store($phone);
     $id = $phone->id;
     unset($phone);
     R::trash($person);
     unset($person);
     $phone = R::load('phone', $id);
     $this->assertNotNull($phone);
     // The phone is not deleted.
 }