Actions

Source Code of This Project

/lib/task/pwpRebuildIndexTask.class.php

<?php
/*
 * This file is part of the pwp package.
 * (c) 2009-2010 Victor Rad' <victor.v.rad[at]gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

class pwpRebuildIndexTask extends sfBaseTask
{
    protected function configure()
    {
        // // add your own arguments here
        // $this->addArguments(array(
        //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
        // ));

        $this->addOptions(array(
                new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
                new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
                new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
                // add your own options here
        ));

        $this->namespace        = 'pwp';
        $this->name             = 'rebuild-index';
        $this->briefDescription = 'Builds all indexes of search from scratch';
        $this->detailedDescription = <<<EOF
The [pwp:rebuildIndex|INFO] task does things.
Call it with:

  [php symfony pwp:rebuildIndex|INFO]
EOF;
    }

    protected function execute($arguments = array(), $options = array())
    {
    //$context = sfContext::createInstance($this->configuration);
    //$this->configuration->loadHelpers('MyUtil');

//    try
//    {
        // initialize the database connection
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
        // do rebuild
        $search = new Search_Composite(new Search_Resume(), new Search_Portfolio(), new Search_News());
        $search->rebuildIndex();
//    }
//    catch (Exception $e)
//    {
//      $this->logSection('err', sprintf('An error in rebuild index of search. %s', $e->getMessage()));
//      return;
//    }

        $this->logSection('tasks', sprintf('All indexs of search is rebuild'));
    }
}