Example #1
0
 public function testLazyLoading()
 {
     //reset registry
     Test_Tool::resetRegistry();
     //find an object with data
     $objectList = new Object_List();
     $objectList->setCondition("o_key like '%_data' and o_type = 'object'");
     $objects = $objectList->load();
     $this->assertTrue($objects[0] instanceof Object_Abstract);
     //check for lazy loading elements
     $this->assertTrue($objects[0]->lazyObjects === null);
     $this->assertTrue(is_array($objects[0]->getLazyObjects()));
     $this->assertTrue($objects[0]->lazyMultihref === null);
     $this->assertTrue(is_array($objects[0]->getLazyMultihref()));
     $this->assertTrue($objects[0]->lazyHref === null);
     $this->assertTrue(is_object($objects[0]->getLazyHref()));
 }
 public function deleteAction()
 {
     if ($this->_getParam("type") == "childs") {
         $parentObject = Object_Abstract::getById($this->_getParam("id"));
         $list = new Object_List();
         $list->setCondition("o_path LIKE '" . $parentObject->getFullPath() . "/%'");
         $list->setLimit(intval($this->_getParam("amount")));
         $list->setOrderKey("LENGTH(o_path)", false);
         $list->setOrder("DESC");
         $objects = $list->load();
         $deletedItems = array();
         foreach ($objects as $object) {
             $deletedItems[] = $object->getFullPath();
             $object->delete();
         }
         $this->_helper->json(array("success" => true, "deleted" => $deletedItems));
     } else {
         if ($this->_getParam("id")) {
             $object = Object_Abstract::getById($this->_getParam("id"));
             if ($object->isAllowed("delete")) {
                 $object->delete();
                 $this->_helper->json(array("success" => true));
             }
         }
     }
     $this->_helper->json(array("success" => false, "message" => "missing_permission"));
 }
Example #3
0
 /**
  * @return void
  */
 public function delete()
 {
     // delete all objects using this class
     $list = new Object_List();
     $list->setCondition("o_classId = ?", $this->getId());
     $list->load();
     foreach ($list->getObjects() as $o) {
         $o->delete();
     }
     $this->deletePhpClasses();
     // empty object cache
     try {
         Pimcore_Model_Cache::clearTag("class_" . $this->getId());
     } catch (Exception $e) {
     }
     // empty output cache
     try {
         Pimcore_Model_Cache::clearTag("output");
     } catch (Exception $e) {
     }
     $this->getResource()->delete();
 }
Example #4
0
 /**
  * @return array
  */
 public function getO_childs($objectTypes = array(self::OBJECT_TYPE_OBJECT, self::OBJECT_TYPE_FOLDER))
 {
     if ($this->o_childs === null || $this->lastGetChildsObjectTypes != $objectTypes) {
         $this->lastGetChildsObjectTypes = $objectTypes;
         $list = new Object_List(true);
         $list->setCondition("o_parentId = ?", $this->getO_id());
         $list->setOrderKey("o_key");
         $list->setOrder("asc");
         $list->setObjectTypes($objectTypes);
         $this->o_childs = $list->load();
     }
     return $this->o_childs;
 }
Example #5
0
 public function testCopyAndDeleteObject()
 {
     $objectList = new Object_List();
     $objectList->setCondition("o_key like '%_data%' and o_type = 'object'");
     $objects = $objectList->load();
     $parent = $objects[0];
     $this->assertTrue($parent instanceof Object_Unittest);
     //remove childs if there are some
     if ($parent->hasChilds()) {
         foreach ($parent->getChilds() as $child) {
             $child->delete();
         }
     }
     $this->assertFalse($parent->hasChilds());
     $service = new Object_Service(User::getById(1));
     //copy as child
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 1);
     //copy as child no. 2
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 2);
     $childs = $parent->getChilds();
     //load all in case of lazy loading fields
     Object_Service::loadAllObjectFields($parent);
     Object_Service::loadAllObjectFields($childs[0]);
     Object_Service::loadAllObjectFields($childs[1]);
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $childs[0], true));
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $childs[1], true));
     //copy recursivley
     $rootNode = Object_Abstract::getById(1);
     $copy = $service->copyRecursive($rootNode, $parent);
     $this->assertTrue($copy->hasChilds());
     Object_Service::loadAllObjectFields($copy);
     $this->assertTrue(count($copy->getChilds()) == 2);
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $copy, true));
     //create empty object
     $emptyObject = new Object_Unittest();
     $emptyObject->setOmitMandatoryCheck(true);
     $emptyObject->setParentId(1);
     $emptyObject->setUserOwner(1);
     $emptyObject->setUserModification(1);
     $emptyObject->setCreationDate(time());
     $emptyObject->setKey(uniqid() . rand(10, 99));
     $emptyObject->save();
     $emptyObject->setOmitMandatoryCheck(false);
     $this->assertFalse(Test_Tool::objectsAreEqual($emptyObject, $copy, true));
     //copy contents
     $emptyObject = $service->copyContents($emptyObject, $copy);
     $this->assertTrue(Test_Tool::objectsAreEqual($emptyObject, $copy, true));
     //todo copy contents must fail if types differ
     //delete recusively
     $shouldBeDeleted[] = $copy->getId();
     $childs = $copy->getChilds();
     foreach ($childs as $child) {
         $shouldBeDeleted[] = $child->getId();
     }
     $copy->delete();
     foreach ($shouldBeDeleted as $id) {
         $o = Object_Abstract::getById($id);
         $this->assertFalse($o instanceof Object_Abstract);
     }
 }