Exemplo n.º 1
0
 /**
  * Initializes the application. Sets up default routes.
  */
 public function __construct()
 {
     if (Curry_Core::$config->curry->pageCache && class_exists('Page')) {
         Page::getCachedPages();
     }
     $this->addRoute(new Curry_Route_ModelRoute());
     $this->addRoute(new Curry_Route_Page());
     Curry_URL::setReverseRouteCallback(array($this, 'reverseRoute'));
 }
Exemplo n.º 2
0
 /**
  * Rebuild the search index.
  *
  * @param bool $ajax
  * @throws Exception
  */
 public static function doRebuild($ajax = false)
 {
     $ses = new Zend_Session_Namespace(__CLASS__);
     $index = Curry_Core::getSearchIndex();
     $app = new Curry_Application();
     Curry_URL::setReverseRouteCallback(array($app, 'reverseRoute'));
     try {
         while ($ses->model < count($ses->models)) {
             $model = $ses->models[$ses->model];
             if ($model === '@custom') {
                 // Trigger custom indexer
                 $ses->model++;
                 $indexerClass = Curry_Core::$config->curry->indexerClass;
                 if ($indexerClass && is_callable(array($indexerClass, 'build'))) {
                     call_user_func(array($indexerClass, 'build'));
                 }
             } else {
                 // Remove old entries
                 if (!$ses->offset) {
                     $hits = $index->find('model:' . $model);
                     foreach ($hits as $hit) {
                         $index->delete($hit->id);
                     }
                 }
                 $query = PropelQuery::from($model);
                 $maxItems = $query->count();
                 $items = $query->offset($ses->offset)->limit($ses->limit)->find();
                 foreach ($items as $item) {
                     $ses->offset++;
                     if (!self::updateItem($item, $index, false)) {
                         $ses->failed++;
                     } else {
                         $ses->success++;
                     }
                 }
                 // move on to next model?
                 if ($ses->offset >= $maxItems || count($items) < $ses->limit) {
                     $ses->model++;
                     $ses->offset = 0;
                     $maxItems = 1;
                 }
             }
             $continue = $ses->model < count($ses->models);
             if ($continue && $ajax) {
                 // Return current status
                 $part = 1 / count($ses->models);
                 $progress = $ses->model * $part + $ses->offset / $maxItems * $part;
                 Curry_Application::returnJson(array('progress' => round(100 * $progress), 'continue' => true, 'status' => "Indexing " . $ses->models[$ses->model] . "..."));
             }
         }
         // All done!
         if ($ajax) {
             $status = "Completed, " . $ses->success . ' entries updated successfully!';
             if ($ses->failed) {
                 $status .= ' ' . $ses->failed . ' items failed.';
             }
             Curry_Application::returnJson(array('progress' => 100, 'continue' => false, 'status' => $status));
         }
     } catch (Exception $e) {
         if ($ajax) {
             Curry_Application::returnJson(array('continue' => false, 'status' => $e->getMessage()));
         } else {
             throw $e;
         }
     }
 }