/** * Check and remove news related to non-existing objects */ function run_opp_news_clean($task, $args) { static $loaded; // load application context if (!$loaded) { define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'fe'); define('SF_ENVIRONMENT', 'task'); define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; sfContext::getInstance(); sfConfig::set('pake', true); error_reporting(E_ALL); $loaded = true; } $start_time = microtime(true); $c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(NewsPeer::ID); $c->addSelectColumn(NewsPeer::RELATED_MONITORABLE_MODEL); $c->addSelectColumn(NewsPeer::RELATED_MONITORABLE_ID); $n_news = NewsPeer::doCount($c); $rs = NewsPeer::doSelectRS($c); $k = 0; $newsids_to_remove = array(); $removed_news = 0; while ($rs->next()) { $news = array(); $news['id'] = $rs->getInt(1); $news['rel_model'] = $rs->getString(2); $news['rel_id'] = $rs->getInt(3); if (opp_check_single_news($news)) { $newsids_to_remove[] = $news['id']; $removed_news++; } $k++; if ($k % 100 == 0) { print "."; } if ($k > 0 && $k % 1000 == 0) { $rem = count($newsids_to_remove); NewsPeer::doDelete($newsids_to_remove); print "processed: {$k}/{$n_news} removed: {$rem} ({$removed_news})\n"; $newsids_to_remove = array(); } } $total_time = microtime(true) - $start_time; echo pakeColor::colorize('All done! ', array('fg' => 'red', 'bold' => true)); echo 'Processed '; echo pakeColor::colorize(count($n_news), array('fg' => 'cyan')); echo ' news in '; echo pakeColor::colorize(sprintf("%f", $total_time), array('fg' => 'cyan')); echo " seconds\n"; }
/** * Returns the number of related News objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related News objects. * @throws PropelException */ public function countNewss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(ImagesPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collNewss === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(NewsPeer::IMAGES_ID, $this->id); $count = NewsPeer::doCount($criteria, false, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(NewsPeer::IMAGES_ID, $this->id); if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) { $count = NewsPeer::doCount($criteria, false, $con); } else { $count = count($this->collNewss); } } else { $count = count($this->collNewss); } } return $count; }
/** * number of new news related to the politician * a new news is a news that has been created after the specified last login timestamp * * @return integer * @author Guglielmo Celata **/ public function getNNewNews(BaseObject $object, $last_login) { $c = new Criteria(); $c->add(NewsPeer::RELATED_MONITORABLE_MODEL, get_class($object)); $c->add(NewsPeer::RELATED_MONITORABLE_ID, $this->getReferenceKey($object)); $c->add(NewsPeer::CREATED_AT, $last_login, Criteria::GREATER_THAN); return NewsPeer::doCount($c); }