Commit 32a4639a authored by zYne's avatar zYne

batch update functionality added

parent 7d7313ab
......@@ -97,35 +97,53 @@ class Doctrine_Search extends Doctrine_Plugin
}
}
public function processPendingTable($tableName, $indexTableName, array $fields, $id, $conn = null)
public function processPending($limit = null, $offset = null)
{
if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::connection();
}
$fields = array_merge($fields, array($id));
$query = 'SELECT ' . implode(', ', $fields) . ' FROM ' . $tableName . ' WHERE '
. $id . ' IN (SELECT foreign_id FROM '
. $indexTableName
. ') ORDER BY ' . $id;
$conn = $this->_options['ownerTable']->getConnection();
$tableName = $this->_options['ownerTable']->getTableName();
$component = $this->_options['ownerTable']->getComponentName();
$id = $this->_options['ownerTable']->getIdentifier();
$class = $this->getOption('className');
$fields = $this->getOption('fields');
$data = $conn->fetchAll($query);
try {
foreach ($data as $row) {
$identifier = $row[$id];
$conn->beginTransaction();
unset($row[$id]);
$query = 'SELECT * FROM ' . $conn->quoteIdentifier($tableName)
. ' WHERE ' . $conn->quoteIdentifier($id)
. ' IN (SELECT ' . $conn->quoteIdentifier($id)
. ' FROM ' . $conn->quoteIdentifier($this->_options['pluginTable']->getTableName())
. ' WHERE keyword IS NULL)';
$rows = $conn->fetchAll($query);
foreach ($rows as $row) {
foreach ($fields as $field) {
$data = $row[$field];
foreach ($row as $field => $data) {
$terms = $this->analyze($data);
foreach ($terms as $pos => $term) {
$conn->insert($indexTableName, array('keyword' => $field,
'position' => $pos,
'field' => $field,
'foreign_id' => $identifier));
$index = new $class();
$index->keyword = $term;
$index->position = $pos;
$index->field = $field;
foreach ((array) $this->_options['ownerTable']->getIdentifier() as $id) {
$index->$id = $row[$id];
}
$index->save();
}
}
}
$conn->commit();
} catch (Doctrine_Exception $e) {
$conn->rollback();
}
}
/**
* insertPending
......@@ -146,6 +164,8 @@ class Doctrine_Search extends Doctrine_Plugin
$className = $this->getOption('className');
$this->_options['ownerTable'] = $table;
if (class_exists($className)) {
return false;
}
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Search_Template
*
* @package Doctrine
* @subpackage Search
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Search_Template extends Doctrine_Template
{
protected $_search;
public function __construct(array $options)
{
$this->_search = new Doctrine_Search($options);
}
public function setUp()
{
$this->_search->buildDefinition($this->_table);
$id = $this->_table->getIdentifier();
$name = $this->_table->getComponentName() . 'Index';
$this->_search->setOption('className', $name);
foreach ((array) $id as $column) {
$foreign[] = strtolower($this->_table->getComponentName() . '_' . $column);
}
$foreign = (count($foreign) > 1) ? $foreign : current($foreign);
$this->hasMany($name, array('local' => $id, 'foreign' => $foreign));
$this->addListener(new Doctrine_Search_Listener($this->_search));
}
}
\ 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