public function loadContents($method, $params = null) { switch ($method) { case 'id+countParents': //$content = $this->loadContents('id', $params); $contents = $this->loadContents('id-deep', ['id' => $params, 'depth' => 2]); $content = $contents->one(); if ($content) { // Set the relations number to content, and content is contents->get($id) //$content->get($params)->setCountParents($this->loadContents('countParents', $params)); $content->setCountParents($this->loadContents('countParents', $params)); $content->setCountAliasId($this->loadContents('count-alias-id', ['alias_id' => $content->getAliasId()])); } return $content; break; default: /* Get metainformation */ $this->loadStructure(); $persistentManager = $this->getManager(); $query = new Query(); $query->setType($method); $query->setCondition($params); $query->setLimits($this->getLimits()); return $persistentManager->load($this, $query); break; } }
public function delete($structureDo, $idContent) { if (!$this->isInitialized($structureDo)) { $this->initialize($structureDo); } // TODO revisar // It is not allowed to delete a content with relations, beacause break integrity $query = new Query(); $query->setType('countParents'); $query->setCondition($idContent); $numRelations = $this->countParents($structureDo, $query); if ($numRelations > 0) { throw new PersistentManagerMongoDBException("Delete failed, the content has {$numRelations} relationships", self::DELETE_FAILED); } else { $mongoCollection = $this->db->selectCollection('content'); $oId = new \MongoId($idContent); $mongoCollection->remove(array('_id' => $oId)); } $this->updateRelations($this->db, \MongoDBRef::create('content', $oId), array()); }
public function delete($structureDo, $idContent) { if ($this->isInitialized($structureDo)) { $this->initialize($structureDo); } $id = $this->mysqli->real_escape_string($idContent); $select = "DELETE FROM content WHERE id = '{$id}'"; // It is not allowed to delete a content with relations, beacause break integrity $query = new Query(); $query->setType('countParents'); $query->setCondition($id); $numRelations = $this->countParents($structureDo, $query); if ($numRelations > 0) { throw new PersistentManagerMySqlException("Delete failed, the content has {$numRelations} relationships", self::DELETE_FAILED); } elseif ($this->mysqli->query($select) !== true) { throw new PersistentManagerMySqlException("Delete failed", self::DELETE_FAILED); } $this->updateTags($id, array()); }