예제 #1
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     echo "Running sfReviewStatsTask ... \n";
     $query = "SELECT r.entity_id, r.sf_review_type_id, r.value, SUM(r.value) sum " . "FROM %s r " . "INNER JOIN %s s ON s.id = r.sf_review_status_id " . "WHERE r.is_active = 1 " . "AND r.sf_review_type_id is not null " . "group by entity_id, sf_review_type_id, value ";
     $query = sprintf($query, SfReviewPeer::TABLE_NAME, SfReviewStatusPeer::TABLE_NAME);
     $connection = Propel::getConnection();
     $statement = $connection->prepare($query);
     //$statement->bindValue(1, 0);
     $statement->execute();
     while ($row = $statement->fetch()) {
         $isNew = false;
         $yesterday = strtotime("yesterday");
         $sfReviewTypeEntity = SfReviewTypeEntityPeer::retrieveByPK($row['sf_review_type_id'], $row['entity_id'], $yesterday, $row['value']);
         if (!$sfReviewTypeEntity) {
             $isNew = true;
             $sfReviewTypeEntity = new SfReviewTypeEntity();
             $sfReviewTypeEntity->setSfReviewTypeId($row['sf_review_type_id']);
             $sfReviewTypeEntity->setEntityId($row['entity_id']);
             $sfReviewTypeEntity->setValue($row['value']);
             $sfReviewTypeEntity->setDate($yesterday);
             $sfReviewTypeEntity->setSum($row['sum']);
             SfReviewTypeEntityPeer::doInsert($sfReviewTypeEntity);
         }
     }
 }
예제 #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      PropelPDO $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(PropelPDO $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 coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSfReviewType !== null) {
             if ($this->aSfReviewType->isModified() || $this->aSfReviewType->isNew()) {
                 $affectedRows += $this->aSfReviewType->save($con);
             }
             $this->setSfReviewType($this->aSfReviewType);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SfReviewTypeEntityPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += SfReviewTypeEntityPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }