Example #1
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(DocumentDataPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = DocumentDataQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(DocumentDataPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.custom", array("role_key" => "document_data")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #2
0
 public static function doDelete($values, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     if ($values instanceof Criteria) {
         // rename for clarity
         $criteria = clone $values;
     } elseif ($values instanceof Document) {
         // it's a model object
         // create criteria based on pk values
         $criteria = $values->buildPkeyCriteria();
     } else {
         // it's a primary key, or an array of pks
         $criteria = new Criteria(self::DATABASE_NAME);
         $criteria->add(PagePeer::ID, (array) $values, Criteria::IN);
     }
     $oHashCriteria = clone $criteria;
     $aHashes = array();
     $stmt = DocumentPeer::doSelectStmt($oHashCriteria->clearSelectColumns()->addSelectColumn(DocumentPeer::HASH));
     while (($row = $stmt->fetch(PDO::FETCH_NUM)) !== false) {
         $sHash = $row[0];
         if (!isset($aHashes[$sHash])) {
             $aHashes[$sHash] = 0;
         }
         $aHashes[$sHash]++;
     }
     foreach ($aHashes as $sHash => $iCount) {
         // Should delete the data object if all documents with this hash are to be deleted
         if (DocumentQuery::create()->filterByHash($sHash)->count() === $iCount) {
             $oDocumentData = DocumentDataQuery::create()->findPk($sHash);
             if ($oDocumentData) {
                 $oDocumentData->delete();
             }
         }
     }
     $stmt->closeCursor();
     return parent::doDelete($criteria, $con);
 }
Example #3
0
 public function setData($mData)
 {
     if (is_resource($mData)) {
         $mData = stream_get_contents($mData);
     }
     $sHash = sha1($mData);
     $sPreviousHash = $this->getHash();
     if ($sHash === $sPreviousHash) {
         return;
     }
     $oOldDocumentData = $this->getDocumentData();
     if ($oOldDocumentData && $oOldDocumentData->countDocuments() <= 1) {
         // Only remaining document is the one to be updated
         $oOldDocumentData->delete();
     }
     $oDocumentData = DocumentDataQuery::create()->findPk($sHash);
     if ($oDocumentData === null) {
         $oDocumentData = new DocumentData();
         $oDocumentData->setHash($sHash);
         $oDocumentData->setDataSize(strlen($mData));
         $oDocumentData->setData($mData);
     }
     $this->setDocumentData($oDocumentData);
     return $this;
 }
Example #4
0
 /**
  * Returns the number of related DocumentData objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related DocumentData objects.
  * @throws PropelException
  */
 public function countDocumentDatasRelatedByUpdatedBy(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collDocumentDatasRelatedByUpdatedByPartial && !$this->isNew();
     if (null === $this->collDocumentDatasRelatedByUpdatedBy || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collDocumentDatasRelatedByUpdatedBy) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getDocumentDatasRelatedByUpdatedBy());
         }
         $query = DocumentDataQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByUserRelatedByUpdatedBy($this)->count($con);
     }
     return count($this->collDocumentDatasRelatedByUpdatedBy);
 }
Example #5
0
 /**
  * Get the associated DocumentData object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return DocumentData The associated DocumentData object.
  * @throws PropelException
  */
 public function getDocumentData(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aDocumentData === null && ($this->hash !== "" && $this->hash !== null) && $doQuery) {
         $this->aDocumentData = DocumentDataQuery::create()->findPk($this->hash, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aDocumentData->addDocuments($this);
            */
     }
     return $this->aDocumentData;
 }
 /**
  * Returns a new DocumentDataQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   DocumentDataQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return DocumentDataQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof DocumentDataQuery) {
         return $criteria;
     }
     $query = new DocumentDataQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }