Commit fa5c28fd authored by zYne's avatar zYne

updated plugin classes to use the refactored main class

parent a9e5a359
......@@ -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);
$columns += $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);
foreach ((array) $id as $column) {
$foreign[] = strtolower(Doctrine::tableize($this->_table->getComponentName()) . '_' . $column);
}
$foreign = (count($foreign) > 1) ? $foreign : current($foreign);
$this->_plugin->buildDefinition($this->_table);
$this->hasMany($className, array('local' => $id, 'foreign' => $foreign));
$this->hasMany($className, array('local' => $id, 'foreign' => $id));
$this->addListener(new Doctrine_Search_Listener($this->_search));
$this->addListener(new Doctrine_Search_Listener($this->_plugin));
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment