Exemplo n.º 1
0
 public function deleteInstancesByOrder(CustomerOrder $order)
 {
     // remove other ExpressCheckout instances for this order
     $f = new ARDeleteFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('ExpressCheckout', 'orderID'), $order->getID()));
     ActiveRecordModel::deleteRecordSet('ExpressCheckout', $f);
 }
Exemplo n.º 2
0
 /**
 *	@todo Rewrite this to use ARUpdateFilter or simply an SQL query to update all values
 
 		As in the original bug report:
 
 			The update query for merging value 799 into 808 would look something like this:
 
 			UPDATE SpecificationItem
 			LEFT JOIN SpecificationItem AS SecondItem ON SpecificationItem.productID=SecondItem.productID AND SecondItem.specFieldValueID=808
 			SET SpecificationItem.specFieldValueID=808
 			WHERE SpecificationItem.specFieldValueID=799 AND SecondItem.specFieldValueID IS NULL
 
 			- it would only update products that do not have value 808 already set (otherwise the query would error because of duplicate SpecificationItem records).
 
 			The remaining records with value 799 will be automatically removed (cascade) when SpecFieldValue 799 is deleted.
 */
 private function mergeFields()
 {
     if (empty($this->mergedFields)) {
         return true;
     }
     $itemClass = call_user_func(array($this->getFieldClass(), 'getSelectValueClass'));
     $valueColumn = call_user_func(array($itemClass, 'getValueIDColumnName'));
     $specificationItemSchema = self::getSchemaInstance($itemClass);
     $foreignKeys = $specificationItemSchema->getForeignKeyList();
     $specFieldReferenceFieldName = '';
     foreach ($foreignKeys as $foreignKey) {
         if ($foreignKey->getForeignClassName() == get_class($this)) {
             $specFieldReferenceFieldName = $foreignKey->getName();
             break;
         }
     }
     $thisSchema = self::getSchemaInstance(get_class($this));
     $primaryKeyList = $thisSchema->getPrimaryKeyList();
     $promaryKey = array_shift($primaryKeyList);
     $mergedFieldsIDs = array();
     foreach ($this->mergedFields as $mergedField) {
         $mergedFieldsIDs[] = $mergedField->getID();
     }
     $inAllItemsExceptThisCondition = new INCond(new ARFieldHandle(get_class($this), $promaryKey->getName()), $mergedFieldsIDs);
     $mergedFieldsIDs[] = $this->getID();
     $inAllItemsCondition = new INCond(new ARFieldHandle($itemClass, $specFieldReferenceFieldName), $mergedFieldsIDs);
     // Create filters
     $mergedSpecificationItemsFilter = new ARSelectFilter();
     $mergedSpecificationItemsFilter->setCondition($inAllItemsCondition);
     // Using IGNORE I'm ignoring duplicate primary keys. Those rows that violate the uniqueness of the primary key are simply not saved
     // Then later I just delete these records and the merge is complete.
     $sql = 'UPDATE IGNORE ' . $itemClass . ' SET ' . $valueColumn . ' = ' . $this->getID() . ' ' . $mergedSpecificationItemsFilter->createString();
     self::getLogger()->logQuery($sql);
     self::executeUpdate($sql);
     $mergedSpecFieldValuesDeleteFilter = new ARDeleteFilter();
     $mergedSpecFieldValuesDeleteFilter->setCondition($inAllItemsExceptThisCondition);
     ActiveRecord::deleteRecordSet(get_class($this), $mergedSpecFieldValuesDeleteFilter);
 }
Exemplo n.º 3
0
 public static function removeByZone(DeliveryZone $zone)
 {
     $filter = new ARDeleteFilter();
     $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'deliveryZoneID'), $zone->getID()));
     return ActiveRecord::deleteRecordSet(__CLASS__, $filter);
 }
Exemplo n.º 4
0
 /**
  * Removes a persisted object (deletes from a database) by an uniqu identifier (record ID)
  *
  * @param string $className
  * @param mixed $recordID
  *
  * @todo remove / replace self::enumerateID method call
  */
 public static function deleteByID($className, $recordID)
 {
     $filter = new ARDeleteFilter();
     $schema = self::getSchemaInstance($className);
     $PKList = $schema->getPrimaryKeyList();
     $PKValueCond = null;
     if (!is_array($recordID)) {
         $PKFieldName = $PKList[key($PKList)]->getName();
         $PKValueCond = new EqualsCond(new ARFieldHandle($className, $PKFieldName), $recordID);
     } else {
         foreach ($PKList as $PK) {
             $cond = new EqualsCond(new ARFieldHandle($className, $PK->getName()), $recordID[$PK->getName()]);
             if (empty($PKValueCond)) {
                 $PKValueCond = $cond;
             } else {
                 $PKValueCond->addAND($cond);
             }
         }
     }
     $hash = self::getRecordHash($recordID);
     if (isset(self::$recordPool[$className][$hash])) {
         $record = self::$recordPool[$className][$hash];
         $record->markAsNotLoaded();
         $record->markAsDeleted();
     }
     $filter->setCondition($PKValueCond);
     self::deleteRecordSet($className, $filter, false);
 }
Exemplo n.º 5
0
 private function updateRoles()
 {
     @unlink($this->getRoleCacheFile());
     if (count($this->canceledRoles) > 0) {
         // Delete canceled associations
         $deleteFilter = new ARDeleteFilter();
         $condition = new EqualsCond(new ARFieldHandle('AccessControlAssociation', "userGroupID"), $this->getID());
         $roleConditions = new EqualsCond(new ARFieldHandle('AccessControlAssociation', "roleID"), reset($this->canceledRoles)->getID());
         foreach ($this->canceledRoles as $key => $role) {
             if ($role->isExistingRecord()) {
                 $roleConditions->addOR(new EqualsCond(new ARFieldHandle('AccessControlAssociation', "roleID"), $role->getID()));
             } else {
                 unset($this->canceledRoles[$key]);
             }
         }
         $condition->addAND($roleConditions);
         $deleteFilter->setCondition($condition);
         if (!empty($this->canceledRoles)) {
             AccessControlAssociation::deleteRecordSet('AccessControlAssociation', $deleteFilter);
         }
     }
     if (count($this->appliedRoles) > 0 && is_object(reset($this->appliedRoles))) {
         // adding new associations is a bit trickier
         // First, find all nodes that are already in DB
         // There is no point to apply them
         $appliedRolesFilter = new ARSelectFilter();
         $appliedIDs = array();
         $condition = new EqualsCond(new ARFieldHandle('AccessControlAssociation', "userGroupID"), $this->getID());
         $roleConditions = new EqualsCond(new ARFieldHandle('AccessControlAssociation', "roleID"), reset($this->appliedRoles)->getID());
         foreach ($this->appliedRoles as $key => $role) {
             if (is_object($role) && $role->isExistingRecord()) {
                 $roleConditions->addOR(new EqualsCond(new ARFieldHandle('AccessControlAssociation', "roleID"), $role->getID()));
             } else {
                 unset($this->appliedRoles[$key]);
             }
         }
         $condition->addAND($roleConditions);
         $appliedRolesFilter->setCondition($condition);
         // Unset already applied nodes
         foreach (AccessControlAssociation::getRecordSetByUserGroup($this, $appliedRolesFilter, self::LOAD_REFERENCES) as $assoc) {
             unset($this->appliedRoles[$assoc->role->get()->getID()]);
         }
         // Apply roles
         foreach ($this->appliedRoles as $role) {
             $assoc = AccessControlAssociation::getNewInstance($this, $role);
             $assoc->save();
         }
     }
 }
Exemplo n.º 6
0
 public static function addNewRolesNames($roleNames, $deleteOther = false)
 {
     // unset meta- roles
     if ($i = array_search('login', $roleNames)) {
         unset($roleNames[$i]);
     }
     if (!is_array($roleNames) || empty($roleNames)) {
         return;
     }
     $filter = new ARSelectFilter();
     $deleteFilter = new ARDeleteFilter();
     $condition = new EqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleNames[0]);
     $deleteCondition = new NotEqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleNames[0]);
     foreach ($roleNames as $roleName) {
         $condition->addOR(new EqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleName));
         $deleteCondition->addAnd(new NotEqualsCond(new ARFieldHandle(__CLASS__, "name"), $roleName));
     }
     $filter->setCondition($condition);
     $deleteFilter->setCondition($deleteCondition);
     if ($deleteOther) {
         self::deleteRecordSet(__CLASS__, $deleteFilter);
     }
     // Find new roles
     $invertedRoleNames = array_flip($roleNames);
     foreach (self::getRecordSet($filter) as $role) {
         if (isset($invertedRoleNames[$role->name->get()])) {
             unset($invertedRoleNames[$role->name->get()]);
         }
     }
     // Add new roles to database
     foreach ($invertedRoleNames as $role => $value) {
         if (!empty($role)) {
             $newRole = Role::getNewInstance($role);
             $newRole->save();
         }
     }
 }