Пример #1
0
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true));
     parent::execute($arguments, $options);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     $this->log('[INFO] Flushing old data...' . "\n");
     $eventlog_flush = EtvaSettingPeer::retrieveByPK('eventlog_flush');
     $flush_range = $eventlog_flush->getValue();
     $con->beginTransaction();
     $affected = 0;
     try {
         $offset_date = date("c", time() - $flush_range * 24 * 60 * 60);
         /*
          * get event records that have creation date outdated
          */
         $c = new Criteria();
         $c->add(EtvaEventPeer::CREATED_AT, $offset_date, Criteria::LESS_THAN);
         $affected = EtvaEventPeer::doDelete($c, $con);
         $con->commit();
         $message = sprintf('Events Log - %d Record(s) deleted after %d day offset', $affected, $flush_range);
         $context->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message)));
         $this->log('[INFO] ' . $message);
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     $logger = new sfFileLogger($context->getEventDispatcher(), array('file' => sfConfig::get("sf_log_dir") . '/cron_status.log'));
     // log the message!
     $logger->log("[INFO] The events flush task ran!", 6);
 }
Пример #2
0
 protected function addFilterCriteria($criteria)
 {
     $filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null;
     if (!$filters) {
         return;
     }
     // GridFilters sends filters as an Array if not json encoded
     if (is_array($filters)) {
         $encoded = false;
     } else {
         $encoded = true;
         $filters = json_decode($filters);
     }
     // loop through filters sent by client
     if (is_array($filters)) {
         for ($i = 0; $i < count($filters); $i++) {
             $filter = $filters[$i];
             // assign filter data (location depends if encoded or not)
             if ($encoded) {
                 $field = $filter->field;
                 $value = $filter->value;
                 $compare = isset($filter->comparison) ? $filter->comparison : null;
                 $filterType = $filter->type;
             } else {
                 $field = $filter['field'];
                 $value = $filter['data']['value'];
                 $compare = isset($filter['data']['comparison']) ? $filter['data']['comparison'] : null;
                 $filterType = $filter['data']['type'];
             }
             if (!$value) {
                 return;
             }
             switch ($filterType) {
                 case 'string':
                     $column = EtvaEventPeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
                     $criteria->add($column, "%{$value}%", Criteria::LIKE);
                     break;
                 case 'list':
                     $column = EtvaEventPeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
                     if (strstr($value, ',')) {
                         $value = explode(',', $value);
                         //                            for ($q=0;$q<count($fi);$q++){
                         //                                $fi[$q] = $fi[$q];
                         //                            }
                         //                            $value = implode(',',$fi);
                         $criteria->add($column, $value, Criteria::IN);
                         //$qs .= " AND ".$field." IN (".$value.")";
                     } else {
                         $criteria->add($column, $value);
                     }
                     break;
                 default:
                     break;
             }
         }
     }
 }