示例#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->aTemplate !== null) {
             if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) {
                 $affectedRows += $this->aTemplate->save($con);
             }
             $this->setTemplate($this->aTemplate);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#2
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->aTaxRule !== null) {
             if ($this->aTaxRule->isModified() || $this->aTaxRule->isNew()) {
                 $affectedRows += $this->aTaxRule->save($con);
             }
             $this->setTaxRule($this->aTaxRule);
         }
         if ($this->aTemplate !== null) {
             if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) {
                 $affectedRows += $this->aTemplate->save($con);
             }
             $this->setTemplate($this->aTemplate);
         }
         if ($this->aBrand !== null) {
             if ($this->aBrand->isModified() || $this->aBrand->isNew()) {
                 $affectedRows += $this->aBrand->save($con);
             }
             $this->setBrand($this->aBrand);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->categoriesScheduledForDeletion !== null) {
             if (!$this->categoriesScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 $pk = $this->getPrimaryKey();
                 foreach ($this->categoriesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
                     $pks[] = array($pk, $remotePk);
                 }
                 ProductCategoryQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->categoriesScheduledForDeletion = null;
             }
             foreach ($this->getCategories() as $category) {
                 if ($category->isModified()) {
                     $category->save($con);
                 }
             }
         } elseif ($this->collCategories) {
             foreach ($this->collCategories as $category) {
                 if ($category->isModified()) {
                     $category->save($con);
                 }
             }
         }
         if ($this->productsRelatedByAccessoryScheduledForDeletion !== null) {
             if (!$this->productsRelatedByAccessoryScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 $pk = $this->getPrimaryKey();
                 foreach ($this->productsRelatedByAccessoryScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
                     $pks[] = array($pk, $remotePk);
                 }
                 AccessoryRelatedByProductIdQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->productsRelatedByAccessoryScheduledForDeletion = null;
             }
             foreach ($this->getProductsRelatedByAccessory() as $productRelatedByAccessory) {
                 if ($productRelatedByAccessory->isModified()) {
                     $productRelatedByAccessory->save($con);
                 }
             }
         } elseif ($this->collProductsRelatedByAccessory) {
             foreach ($this->collProductsRelatedByAccessory as $productRelatedByAccessory) {
                 if ($productRelatedByAccessory->isModified()) {
                     $productRelatedByAccessory->save($con);
                 }
             }
         }
         if ($this->productsRelatedByProductIdScheduledForDeletion !== null) {
             if (!$this->productsRelatedByProductIdScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 $pk = $this->getPrimaryKey();
                 foreach ($this->productsRelatedByProductIdScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
                     $pks[] = array($pk, $remotePk);
                 }
                 AccessoryRelatedByAccessoryQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->productsRelatedByProductIdScheduledForDeletion = null;
             }
             foreach ($this->getProductsRelatedByProductId() as $productRelatedByProductId) {
                 if ($productRelatedByProductId->isModified()) {
                     $productRelatedByProductId->save($con);
                 }
             }
         } elseif ($this->collProductsRelatedByProductId) {
             foreach ($this->collProductsRelatedByProductId as $productRelatedByProductId) {
                 if ($productRelatedByProductId->isModified()) {
                     $productRelatedByProductId->save($con);
                 }
             }
         }
         if ($this->productCategoriesScheduledForDeletion !== null) {
             if (!$this->productCategoriesScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductCategoryQuery::create()->filterByPrimaryKeys($this->productCategoriesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productCategoriesScheduledForDeletion = null;
             }
         }
         if ($this->collProductCategories !== null) {
             foreach ($this->collProductCategories as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->featureProductsScheduledForDeletion !== null) {
             if (!$this->featureProductsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\FeatureProductQuery::create()->filterByPrimaryKeys($this->featureProductsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->featureProductsScheduledForDeletion = null;
             }
         }
         if ($this->collFeatureProducts !== null) {
             foreach ($this->collFeatureProducts as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productSaleElementssScheduledForDeletion !== null) {
             if (!$this->productSaleElementssScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductSaleElementsQuery::create()->filterByPrimaryKeys($this->productSaleElementssScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productSaleElementssScheduledForDeletion = null;
             }
         }
         if ($this->collProductSaleElementss !== null) {
             foreach ($this->collProductSaleElementss as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productImagesScheduledForDeletion !== null) {
             if (!$this->productImagesScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductImageQuery::create()->filterByPrimaryKeys($this->productImagesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productImagesScheduledForDeletion = null;
             }
         }
         if ($this->collProductImages !== null) {
             foreach ($this->collProductImages as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productDocumentsScheduledForDeletion !== null) {
             if (!$this->productDocumentsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductDocumentQuery::create()->filterByPrimaryKeys($this->productDocumentsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productDocumentsScheduledForDeletion = null;
             }
         }
         if ($this->collProductDocuments !== null) {
             foreach ($this->collProductDocuments as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->accessoriesRelatedByProductIdScheduledForDeletion !== null) {
             if (!$this->accessoriesRelatedByProductIdScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\AccessoryQuery::create()->filterByPrimaryKeys($this->accessoriesRelatedByProductIdScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->accessoriesRelatedByProductIdScheduledForDeletion = null;
             }
         }
         if ($this->collAccessoriesRelatedByProductId !== null) {
             foreach ($this->collAccessoriesRelatedByProductId as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->accessoriesRelatedByAccessoryScheduledForDeletion !== null) {
             if (!$this->accessoriesRelatedByAccessoryScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\AccessoryQuery::create()->filterByPrimaryKeys($this->accessoriesRelatedByAccessoryScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->accessoriesRelatedByAccessoryScheduledForDeletion = null;
             }
         }
         if ($this->collAccessoriesRelatedByAccessory !== null) {
             foreach ($this->collAccessoriesRelatedByAccessory as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->cartItemsScheduledForDeletion !== null) {
             if (!$this->cartItemsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\CartItemQuery::create()->filterByPrimaryKeys($this->cartItemsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->cartItemsScheduledForDeletion = null;
             }
         }
         if ($this->collCartItems !== null) {
             foreach ($this->collCartItems as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productAssociatedContentsScheduledForDeletion !== null) {
             if (!$this->productAssociatedContentsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductAssociatedContentQuery::create()->filterByPrimaryKeys($this->productAssociatedContentsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productAssociatedContentsScheduledForDeletion = null;
             }
         }
         if ($this->collProductAssociatedContents !== null) {
             foreach ($this->collProductAssociatedContents as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->saleProductsScheduledForDeletion !== null) {
             if (!$this->saleProductsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\SaleProductQuery::create()->filterByPrimaryKeys($this->saleProductsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->saleProductsScheduledForDeletion = null;
             }
         }
         if ($this->collSaleProducts !== null) {
             foreach ($this->collSaleProducts as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productI18nsScheduledForDeletion !== null) {
             if (!$this->productI18nsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductI18nQuery::create()->filterByPrimaryKeys($this->productI18nsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productI18nsScheduledForDeletion = null;
             }
         }
         if ($this->collProductI18ns !== null) {
             foreach ($this->collProductI18ns as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->productVersionsScheduledForDeletion !== null) {
             if (!$this->productVersionsScheduledForDeletion->isEmpty()) {
                 \Thelia\Model\ProductVersionQuery::create()->filterByPrimaryKeys($this->productVersionsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->productVersionsScheduledForDeletion = null;
             }
         }
         if ($this->collProductVersions !== null) {
             foreach ($this->collProductVersions as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }