Esempio n. 1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->awork !== null) {
             if ($this->awork->isModified() || $this->awork->isNew()) {
                 $affectedRows += $this->awork->save($con);
             }
             $this->setwork($this->awork);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->topicsScheduledForDeletion !== null) {
             if (!$this->topicsScheduledForDeletion->isEmpty()) {
                 \SpoilerWiki\TopicQuery::create()->filterByPrimaryKeys($this->topicsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->topicsScheduledForDeletion = null;
             }
         }
         if ($this->collTopics !== null) {
             foreach ($this->collTopics as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->snippetsScheduledForDeletion !== null) {
             if (!$this->snippetsScheduledForDeletion->isEmpty()) {
                 \SpoilerWiki\SnippetQuery::create()->filterByPrimaryKeys($this->snippetsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->snippetsScheduledForDeletion = null;
             }
         }
         if ($this->collSnippets !== null) {
             foreach ($this->collSnippets as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->summariesScheduledForDeletion !== null) {
             if (!$this->summariesScheduledForDeletion->isEmpty()) {
                 \SpoilerWiki\SummaryQuery::create()->filterByPrimaryKeys($this->summariesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->summariesScheduledForDeletion = null;
             }
         }
         if ($this->collSummaries !== null) {
             foreach ($this->collSummaries as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Esempio n. 2
0
 /**
  * Exchange the rank of the object with the one passed as argument, and saves both objects
  *
  * @param     ChildWork $object
  * @param     ConnectionInterface $con optional connection
  *
  * @return    $this|ChildWork the current object
  *
  * @throws Exception if the database cannot execute the two updates
  */
 public function swapWith($object, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(WorkTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con, $object) {
         $oldRank = $this->getSortableRank();
         $newRank = $object->getSortableRank();
         $this->setSortableRank($newRank);
         $object->setSortableRank($oldRank);
         $this->save($con);
         $object->save($con);
     });
     return $this;
 }