/**
  * Executes show action.
  *
  * @param sfWebRequest $request
  */
 public function executeShow(sfWebRequest $request)
 {
     $this->nc_change_log_entry = ncChangeLogEntryPeer::retrieveByPK($request->getParameter('id'));
     $this->forward404Unless($this->nc_change_log_entry);
     $this->nc_change_log_entry = $this->nc_change_log_entry->getAdapter();
     $this->object = $this->nc_change_log_entry->getObject();
 }
 public static function getChangeLogOfObject($class, $pk = null, $from_date = null, $to_date = null)
 {
     $c = new Criteria();
     $c->add(ncChangeLogEntryPeer::CLASS_NAME, $class);
     if (!is_null($pk)) {
         $c->add(ncChangeLogEntryPeer::OBJECT_PK, $pk);
     }
     $criterion1 = $c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $from_date, Criteria::GREATER_EQUAL);
     $criterion2 = $c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $to_date, Criteria::LESS_EQUAL);
     $c->addAnd($criterion1);
     $c->addAnd($criterion2);
     return self::convertToAdapter(ncChangeLogEntryPeer::doSelect($c));
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->createContextInstance();
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     /** @var $connection PropelPDO */
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $username = '******';
     $date_from = '2013-11-23 00:00:00';
     $date_to = '2013-11-23 23:59:59';
     $class = 'CourseSubjectStudentMark';
     /** @var $user sfGuardSecurityUser */
     $user = sfContext::getInstance()->getUser();
     $sf_user = sfGuardUserPeer::retrieveByUsername($username);
     $user->signin($sf_user, false);
     $connection->beginTransaction();
     try {
         $c = new Criteria();
         $c->add(ncChangeLogEntryPeer::CLASS_NAME, $class);
         $c->add(ncChangeLogEntryPeer::USERNAME, $username);
         $cri = $c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_from, Criteria::GREATER_EQUAL);
         $cri->addAnd($c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_to, Criteria::LESS_EQUAL));
         $c->add($cri);
         $cambios = ncChangeLogEntryPeer::doSelect($c, $connection);
         /** @var $nc_change_log_entry ncChangeLogEntry */
         foreach ($cambios as $nc_change_log_entry) {
             $obj = unserialize(base64_decode($nc_change_log_entry->getChangesDetail()));
             if (isset($obj['changes']) && isset($obj['changes']['mark'])) {
                 $old = $obj['changes']['mark']['raw']['old'];
                 $new = $obj['changes']['mark']['raw']['new'];
                 $id = $obj['pk'];
                 $mark = CourseSubjectStudentMarkPeer::retrieveByPK($id, $connection);
                 $mark->setMark($old);
                 $mark->save($connection);
             }
         }
         $connection->commit();
     } catch (Exception $e) {
         $connection->rollBack();
         $this->log($e->getMessage());
         $this->log($e->getTraceAsString());
     }
 }
Example #4
0
 /**
  * Retrieve an array with the following structure
  *  array(
  *    'related_column_name' => array ( ncChangeLogEntries...)
  *    );
  * @return mixed An array of the ncChangeLogEntries of the related columns.
  */
 public function getRelatedTablesChangeLogEntries()
 {
     return ncChangeLogEntryPeer::getRelatedTablesChangeLog($this->getObject());
 }
 /**
  * Get $object's Related ChangeLog and return it as an array of ncChangeLogAdapters.
  * If no entry is found, answer an empty Array.
  *
  * This methods inspects the columns of the object's table and if one of them is a foreign key,
  * it returns the change log of the referenced object.
  *
  * @param mixed $object
  * @param date $from_date
  * @param transformToAdapters
  *
  * @return Array of ncChangeLogEntry
  */
 public static function get1NRelatedChangeLog($object, $from_date = null, $transformToAdapters = true)
 {
     $relatedChangeLog = array();
     if (!is_null($object)) {
         $class = get_class($object);
         $peer = constant($class . '::PEER');
         $tableMap = call_user_func(array($peer, 'getTableMap'));
         foreach ($tableMap->getColumns() as $c) {
             if ($c->isForeignKey()) {
                 $method = 'get' . $c->getPhpName();
                 $relatedTableName = $c->getRelatedTableName();
                 $relatedColName = $c->getRelatedColumnName();
                 $relatedPeerClass = ncClassFinder::getInstance()->findPeerClassName($relatedTableName);
                 $relatedClass = ncClassFinder::getInstance()->findClassName($relatedTableName, $relatedPeerClass);
                 $criteria = new Criteria();
                 $criteria->add(ncChangeLogEntryPeer::CLASS_NAME, $relatedClass);
                 $criteria->add(ncChangeLogEntryPeer::OBJECT_PK, $object->{$method}());
                 if (!is_null($from_date)) {
                     $criteria->add(ncChangeLogEntryPeer::CREATED_AT, $from_date, Criteria::GREATER_THAN);
                 }
                 $relatedChangeLog[$c->getName()] = ncChangeLogEntryPeer::doSelect($criteria);
             }
         }
     }
     return $transformToAdapters ? self::getRelatedAdapters($relatedChangeLog) : $relatedChangeLog;
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase('propel')->getConnection();
     $this->registerBehavior();
     //Counters
     $migrated = 0;
     $notNeeded = 0;
     $errors = 0;
     if ($this->makeBackupQuestion()) {
         echo "\n";
         //Query database
         $entries = ncChangeLogEntryPeer::doSelect(new Criteria());
         foreach ($entries as $i => $e) {
             $this->printFixedLenghtMessage(str_replace(array('%%id%%', '%%class%%', '%%pk%%'), array($e->getId(), $e->getClassName(), $e->getPrimaryKey()), "Migratring entry '%%id%%' of class '%%class%%' with primary key '%%pk%%'..."));
             if ($this->migrateOne($e)) {
                 try {
                     if ($options['go']) {
                         $e->save();
                     }
                     $migrated++;
                     echo "[   MIGRATED ]\n";
                 } catch (Exception $e) {
                     echo "[      ERROR ]\n\t\t" . $e->getMessage() . "\n";
                     $errors++;
                 }
             } else {
                 $notNeeded++;
                 echo "[ NOT NEEDED ]\n";
             }
         }
         echo "\n\n*********************************\nMigrated:                    {$migrated}\nErrors:                      {$errors}\nDo not need migration:       {$notNeeded}\n\nTotal:                       " . count($entries) . "\n*********************************\n\n";
         if (!$options['go']) {
             echo "\n*** DUMMY MODE ENABLED. To enable writes to database use the '--go' option. ***\n\n";
         }
     }
 }