コード例 #1
0
/**
* 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";
}
コード例 #2
0
ファイル: BaseNews.php プロジェクト: Ayaan123/alumnisangam
 public function delete($con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(NewsPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         NewsPeer::doDelete($this, $con);
         $this->setDeleted(true);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
コード例 #3
0
 /**
  * delete all news related to this object before deleting the object
  *
  * @param string $con 
  * @return void
  * @author Guglielmo Celata
  */
 public function delete($con = null)
 {
     try {
         $c = new Criteria();
         $c->add(NewsPeer::RELATED_MONITORABLE_MODEL, 'OppAtto');
         $c->add(NewsPeer::RELATED_MONITORABLE_ID, $this->getPrimaryKey());
         NewsPeer::doDelete($c);
     } catch (Exception $e) {
         throw new deppPropelActAsNewsGeneratorException('Unable to delete related monitorable object records');
     }
     parent::delete($con);
 }
コード例 #4
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     foreach (sfMixer::getCallables('BaseNews:delete:pre') as $callable) {
         $ret = call_user_func($callable, $this, $con);
         if ($ret) {
             return;
         }
     }
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(NewsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         NewsPeer::doDelete($this, $con);
         $this->setDeleted(true);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     foreach (sfMixer::getCallables('BaseNews:delete:post') as $callable) {
         call_user_func($callable, $this, $con);
     }
 }
 /**
  * Deletes all news originated from a generator object (delete cascade emulation)
  * 
  * @param  BaseObject  $object
  */
 public function preDelete(BaseObject $object)
 {
     try {
         $c = new Criteria();
         $c->add(NewsPeer::GENERATOR_MODEL, get_class($object));
         $c->add(NewsPeer::GENERATOR_PRIMARY_KEYS, serialize($this->getPrimaryKeysArray($object)));
         NewsPeer::doDelete($c);
     } catch (Exception $e) {
         throw new deppPropelActAsNewsGeneratorException('Unable to delete related monitorable object records');
     }
 }