updated plugin classes to use the refactored main class
This commit is contained in:
parent
a9e5a35917
commit
fa5c28fde0
@ -96,6 +96,11 @@ class Doctrine_AuditLog extends Doctrine_Plugin
|
||||
$id = $table->getIdentifier();
|
||||
|
||||
$options = array('className' => $className);
|
||||
|
||||
$relations = array($name => array('local' => $local,
|
||||
'foreign' => $id,
|
||||
'onDelete' => 'CASCADE',
|
||||
'onUpdate' => 'CASCADE'));
|
||||
|
||||
$this->generateClass($options, $columns, array());
|
||||
|
||||
|
@ -118,7 +118,7 @@ class Doctrine_Plugin
|
||||
unset($def['sequence']);
|
||||
unset($def['primary']);
|
||||
|
||||
$col = strtolower(Doctrine::tableize($table->getComponentName()) . '_' . $column);
|
||||
$col = $column;
|
||||
|
||||
$def['primary'] = true;
|
||||
$fk[$col] = $def;
|
||||
|
@ -68,13 +68,21 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
$name = $record->getTable()->getComponentName();
|
||||
|
||||
if ($this->_options['batchUpdates'] === true) {
|
||||
$conn->insert(Doctrine::tableize($class), array('foreign_id' => $id));
|
||||
|
||||
$conn = $record->getTable()->getConnection();
|
||||
|
||||
$index = new $class();
|
||||
foreach ($record->identifier() as $id => $value) {
|
||||
$index->$id = $value;
|
||||
}
|
||||
|
||||
$index->save();
|
||||
} else {
|
||||
foreach ($fields as $field) {
|
||||
$data = $record->get($field);
|
||||
|
||||
$terms = $this->analyze($data);
|
||||
|
||||
|
||||
foreach ($terms as $pos => $term) {
|
||||
$index = new $class();
|
||||
|
||||
@ -82,7 +90,7 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
$index->position = $pos;
|
||||
$index->field = $field;
|
||||
$index->$name = $record;
|
||||
|
||||
|
||||
$index->save();
|
||||
}
|
||||
}
|
||||
@ -144,12 +152,10 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
|
||||
$columns = array('keyword' => array('type' => 'string',
|
||||
'length' => 200,
|
||||
'notnull' => true,
|
||||
'primary' => true,
|
||||
),
|
||||
'field' => array('type' => 'string',
|
||||
'length' => 50,
|
||||
'notnull' => true,
|
||||
'primary' => true),
|
||||
'position' => array('type' => 'integer',
|
||||
'length' => 8,
|
||||
@ -159,34 +165,14 @@ class Doctrine_Search extends Doctrine_Plugin
|
||||
$id = $table->getIdentifier();
|
||||
|
||||
$options = array('className' => $className);
|
||||
|
||||
|
||||
$fk = array();
|
||||
foreach ((array) $id as $column) {
|
||||
$def = $table->getDefinitionOf($column);
|
||||
|
||||
unset($def['autoincrement']);
|
||||
unset($def['sequence']);
|
||||
unset($def['primary']);
|
||||
|
||||
$col = strtolower(Doctrine::tableize($name) . '_' . $column);
|
||||
|
||||
$def['primary'] = true;
|
||||
$fk[$col] = $def;
|
||||
}
|
||||
|
||||
$local = (count($fk) > 1) ? array_keys($fk) : key($fk);
|
||||
|
||||
$relations = array($name => array('local' => $local,
|
||||
'foreign' => $id,
|
||||
'onDelete' => 'CASCADE',
|
||||
'onUpdate' => 'CASCADE'));
|
||||
|
||||
|
||||
$fk = $this->generateForeignKeys($table);
|
||||
$columns += $fk;
|
||||
|
||||
|
||||
$relations = $this->generateRelation($table, $fk);
|
||||
|
||||
$this->generateClass($options, $columns, $relations);
|
||||
|
||||
|
||||
$this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);
|
||||
|
||||
return true;
|
||||
|
@ -32,32 +32,30 @@
|
||||
*/
|
||||
class Doctrine_Template_Searchable extends Doctrine_Template
|
||||
{
|
||||
protected $_search;
|
||||
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->_search = new Doctrine_Search($options);
|
||||
$this->_plugin = new Doctrine_Search($options);
|
||||
}
|
||||
|
||||
public function getPlugin()
|
||||
{
|
||||
return $this->_plugin;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$id = $this->_table->getIdentifier();
|
||||
$name = $this->_table->getComponentName();
|
||||
$className = $this->_search->getOption('className');
|
||||
$className = $this->_plugin->getOption('className');
|
||||
|
||||
if (strpos($className, '%CLASS%') !== false) {
|
||||
$this->_search->setOption('className', str_replace('%CLASS%', $name, $className));
|
||||
$className = $this->_search->getOption('className');
|
||||
$this->_plugin->setOption('className', str_replace('%CLASS%', $name, $className));
|
||||
$className = $this->_plugin->getOption('className');
|
||||
}
|
||||
$this->_search->buildDefinition($this->_table);
|
||||
$this->_plugin->buildDefinition($this->_table);
|
||||
|
||||
foreach ((array) $id as $column) {
|
||||
$foreign[] = strtolower(Doctrine::tableize($this->_table->getComponentName()) . '_' . $column);
|
||||
}
|
||||
$this->hasMany($className, array('local' => $id, 'foreign' => $id));
|
||||
|
||||
$foreign = (count($foreign) > 1) ? $foreign : current($foreign);
|
||||
|
||||
$this->hasMany($className, array('local' => $id, 'foreign' => $foreign));
|
||||
|
||||
$this->addListener(new Doctrine_Search_Listener($this->_search));
|
||||
$this->addListener(new Doctrine_Search_Listener($this->_plugin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user