Development

Changeset 7021 for plugins

You must first sign up to be able to contribute.

Changeset 7021 for plugins

Show
Ignore:
Timestamp:
01/12/08 04:10:41 (5 years ago)
Author:
Carl.Vondrick
Message:

sfLucene: added ability to lock the Propel behavior (see forum topic 10673)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfLucenePlugin/trunk/CHANGELOG

    r6922 r7021  
    2020  * BC: sfLuceneCriteria constructor now requires sfLucene instance 
    2121  * Refactored highlighting system 
     22  * Added ability to lock the Propel behavior. 
    2223 
    2324Version 0.1.1 Beta 
  • plugins/sfLucenePlugin/trunk/README

    r6922 r7021  
    154154after the class declaration.  So, for a blog, you would open project/lib/model/BlogPost.php and append the above, replacing "!MyModel" with "!BlogPost". 
    155155 
     156If you wish to disable the Propel behavior so that no indexing can occur, you can simply do: 
     157{{{ 
     158sfLucenePropelBehavior::setLock(true); // disables Propel behavior, no indexing 
     159sfLucenePropelBehavior::setLock(false); // enables Propel behavior, does index 
     160}}} 
     161 
     162By default, the behavior is not locked so indexing does occur. 
     163 
    156164== Advanced Model Settings == 
    157165You can configure the model even more.  If the peer does not follow symfony's naming conventions, you can specify a new one with in the project level search.yml: 
  • plugins/sfLucenePlugin/trunk/lib/behavior/sfLucenePropelBehavior.class.php

    r6733 r7021  
    2828 
    2929  /** 
     30   * If true, then nothing can be added to the queues. 
     31   */ 
     32  static protected $locked = false; 
     33 
     34  /** 
    3035   * Adds the node to the queue if is modified or is new. 
    3136   * 
     
    3641  public function preSave($node) 
    3742  { 
     43    if (self::$locked) 
     44    { 
     45      return; 
     46    } 
     47 
    3848    if ($node->isModified() || $node->isNew()) 
    3949    { 
     
    7787  public function preDelete($node) 
    7888  { 
     89    if (self::$locked) 
     90    { 
     91      return; 
     92    } 
     93 
    7994    if (!$node->isNew()) 
    8095    { 
     
    192207    return sfLucenePropelInitializer::getInstance(); 
    193208  } 
     209 
     210  /** 
     211   * Locks the Propel behavior, so nothing can be queued. 
     212   * @param bool $to If true, the behavior is locked.  If false, the behavior is unlocked. 
     213   */ 
     214  static public function setLock($to) 
     215  { 
     216    self::$locked = (bool) $to; 
     217  } 
    194218} 
  • plugins/sfLucenePlugin/trunk/test/unit/behavior/sfLucenePropelBehaviorTest.php

    r6960 r7021  
    1717require dirname(__FILE__) . '/../../bootstrap/unit.php'; 
    1818 
    19 $t = new limeade_test(26, limeade_output::get()); 
     19$t = new limeade_test(30, limeade_output::get()); 
    2020$limeade = new limeade_sf($t); 
    2121$app = $limeade->bootstrap(); 
     
    5555  { 
    5656    return $this->getSearchInstances($node); 
     57  } 
     58 
     59  public function clear() 
     60  { 
     61    $this->saveQueue = array(); 
     62    $this->deleteQueue = array(); 
    5763  } 
    5864} 
     
    154160$t->is($behavior->_getDeleteQueue(), array(1 => $m2), '->postDelete() removes deleting model from the queue'); 
    155161 
     162$t->diag('testing ::setLock()'); 
     163 
     164$behavior->clear(); 
     165 
     166sfLucenePropelBehavior::setLock(true); 
     167 
     168$m1->setCoolness(4); 
     169 
     170$behavior->preSave($m1); 
     171$t->is(count($behavior->_getSaveQueue()), 0, '::setLock() disables the save queue'); 
     172 
     173$behavior->preDelete($m1); 
     174$t->is(count($behavior->_getDeleteQueue()), 0, '::setLock() disables the delete queue'); 
     175 
     176$behavior->clear(); 
     177 
     178sfLucenePropelBehavior::setLock(false); 
     179 
     180$behavior->preSave($m1); 
     181$t->is(count($behavior->_getSaveQueue()), 1, '::setLock() enables the save queue'); 
     182 
     183$behavior->preDelete($m1); 
     184$t->is(count($behavior->_getDeleteQueue()), 1, '::setLock() enables the delete queue'); 
     185 
     186$behavior->clear(); 
     187 
     188foreach (array($m1, $m2, $m3, $m3) as $m) 
     189{ 
     190  $indexer = new sfLucenePropelIndexer(sfLucene::getInstance('testLucene', 'en'), $m); 
     191  $indexer->delete(); 
     192} 
     193 
    156194$t->diag('testing ->insertIndex()'); 
    157195