From fa5c28fde0a19cd4542ad9b1935f544cbcfaa084 Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 13 Oct 2007 16:49:42 +0000 Subject: [PATCH] updated plugin classes to use the refactored main class --- lib/Doctrine/AuditLog.php | 5 +++ lib/Doctrine/Plugin.php | 2 +- lib/Doctrine/Search.php | 46 ++++++++++------------------ lib/Doctrine/Template/Searchable.php | 30 +++++++++--------- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/lib/Doctrine/AuditLog.php b/lib/Doctrine/AuditLog.php index f41c223c0..958ee885e 100644 --- a/lib/Doctrine/AuditLog.php +++ b/lib/Doctrine/AuditLog.php @@ -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()); diff --git a/lib/Doctrine/Plugin.php b/lib/Doctrine/Plugin.php index 9a6a7a1c9..7f47a48f9 100644 --- a/lib/Doctrine/Plugin.php +++ b/lib/Doctrine/Plugin.php @@ -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; diff --git a/lib/Doctrine/Search.php b/lib/Doctrine/Search.php index 77f4139b2..b6790eb6e 100644 --- a/lib/Doctrine/Search.php +++ b/lib/Doctrine/Search.php @@ -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; diff --git a/lib/Doctrine/Template/Searchable.php b/lib/Doctrine/Template/Searchable.php index 893a77ef2..0e6bdf2a1 100644 --- a/lib/Doctrine/Template/Searchable.php +++ b/lib/Doctrine/Template/Searchable.php @@ -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)); } -} \ No newline at end of file +}