mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Fix CS
This commit is contained in:
@@ -17,122 +17,112 @@
|
||||
*/
|
||||
class sphinxrt
|
||||
{
|
||||
protected static $_instance;
|
||||
protected static $_failure = false;
|
||||
protected $connection;
|
||||
|
||||
protected static $_instance;
|
||||
protected static $_failure = false;
|
||||
protected $connection;
|
||||
protected function __construct(registry $registry)
|
||||
{
|
||||
try {
|
||||
$dsn = sprintf('mysql:host=%s;port=%s;', $registry->get('GV_sphinx_rt_host'), $registry->get('GV_sphinx_rt_port'));
|
||||
$this->connection = @new PDO($dsn);
|
||||
} catch (Exception $e) {
|
||||
self::$_failure = true;
|
||||
throw new Exception('Unable to connect to sphinx rt');
|
||||
}
|
||||
|
||||
protected function __construct(registry $registry)
|
||||
{
|
||||
try
|
||||
{
|
||||
$dsn = sprintf('mysql:host=%s;port=%s;', $registry->get('GV_sphinx_rt_host'), $registry->get('GV_sphinx_rt_port'));
|
||||
$this->connection = @new PDO($dsn);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
self::$_failure = true;
|
||||
throw new Exception('Unable to connect to sphinx rt');
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return sphinxrt
|
||||
*/
|
||||
public static function get_instance(registry $registry, $retry_on_failure = false)
|
||||
{
|
||||
if ( ! $retry_on_failure && self::$_failure === true) {
|
||||
throw new Exception('Unable to connect to sphinx rt, try set retry_on_failure true');
|
||||
}
|
||||
if ( ! self::$_instance instanceof self) {
|
||||
self::$_instance = new self($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return sphinxrt
|
||||
*/
|
||||
public static function get_instance(registry $registry, $retry_on_failure = false)
|
||||
{
|
||||
if ( ! $retry_on_failure && self::$_failure === true)
|
||||
{
|
||||
throw new Exception('Unable to connect to sphinx rt, try set retry_on_failure true');
|
||||
}
|
||||
if ( ! self::$_instance instanceof self)
|
||||
{
|
||||
self::$_instance = new self($registry);
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an index
|
||||
*
|
||||
* @param array $index_ids
|
||||
* @param <type> $rt_id
|
||||
* @param <type> $meta_id
|
||||
* @return sphinxrt
|
||||
*/
|
||||
public function delete(Array $index_ids, $rt_id, $id)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
require_once $registry->get('GV_RootPath') . 'lib/vendor/sphinx/sphinxapi.php';
|
||||
|
||||
$cl = new SphinxClient();
|
||||
|
||||
$cl->SetServer($registry->get('GV_sphinx_host'), (int) $registry->get('GV_sphinx_port'));
|
||||
$cl->SetConnectTimeout(1);
|
||||
|
||||
foreach ($index_ids as $index_id)
|
||||
$cl->UpdateAttributes($index_id, array("deleted"), array($id => array(1)));
|
||||
|
||||
if ($rt_id)
|
||||
/**
|
||||
* Delete an index
|
||||
*
|
||||
* @param array $index_ids
|
||||
* @param <type> $rt_id
|
||||
* @param <type> $meta_id
|
||||
* @return sphinxrt
|
||||
*/
|
||||
public function delete(Array $index_ids, $rt_id, $id)
|
||||
{
|
||||
$this->connection->beginTransaction();
|
||||
$sql = "DELETE FROM " . $rt_id . " WHERE id = " . (int) $id . "";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
$this->connection->commit();
|
||||
$registry = registry::get_instance();
|
||||
require_once $registry->get('GV_RootPath') . 'lib/vendor/sphinx/sphinxapi.php';
|
||||
|
||||
$cl = new SphinxClient();
|
||||
|
||||
$cl->SetServer($registry->get('GV_sphinx_host'), (int) $registry->get('GV_sphinx_port'));
|
||||
$cl->SetConnectTimeout(1);
|
||||
|
||||
foreach ($index_ids as $index_id)
|
||||
$cl->UpdateAttributes($index_id, array("deleted"), array($id => array(1)));
|
||||
|
||||
if ($rt_id) {
|
||||
$this->connection->beginTransaction();
|
||||
$sql = "DELETE FROM " . $rt_id . " WHERE id = " . (int) $id . "";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
$this->connection->commit();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function update_status(Array $index_ids, $sbas_id, $record_id, $status)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
require_once $registry->get('GV_RootPath') . 'lib/vendor/sphinx/sphinxapi.php';
|
||||
|
||||
$cl = new SphinxClient();
|
||||
|
||||
if ($cl->Status() === false)
|
||||
public function update_status(Array $index_ids, $sbas_id, $record_id, $status)
|
||||
{
|
||||
return $this;
|
||||
$registry = registry::get_instance();
|
||||
require_once $registry->get('GV_RootPath') . 'lib/vendor/sphinx/sphinxapi.php';
|
||||
|
||||
$cl = new SphinxClient();
|
||||
|
||||
if ($cl->Status() === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$cl->SetServer($registry->get('GV_sphinx_host'), (int) $registry->get('GV_sphinx_port'));
|
||||
$cl->SetConnectTimeout(1);
|
||||
|
||||
|
||||
$status = strrev($status);
|
||||
$new_stat = array();
|
||||
for ($i = 4; $i < strlen($status); $i ++ ) {
|
||||
if (substr($status, $i, 1) == '1')
|
||||
$new_stat[] = crc32($sbas_id . '_' . $i);
|
||||
}
|
||||
|
||||
foreach ($index_ids as $index_id) {
|
||||
$cl->UpdateAttributes($index_id, array("status"), array($record_id => array($new_stat)), true);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$cl->SetServer($registry->get('GV_sphinx_host'), (int) $registry->get('GV_sphinx_port'));
|
||||
$cl->SetConnectTimeout(1);
|
||||
|
||||
|
||||
$status = strrev($status);
|
||||
$new_stat = array();
|
||||
for ($i = 4; $i < strlen($status); $i ++ )
|
||||
public function replace_in_metas($rt_id, $meta_id, $tag_id, $record_id, $sbas_id, $coll_id, $grouping, $type, $content, $business, DateTime $created)
|
||||
{
|
||||
if (substr($status, $i, 1) == '1')
|
||||
$new_stat[] = crc32($sbas_id . '_' . $i);
|
||||
}
|
||||
$crc_sbas_tag = crc32($sbas_id . '_' . $tag_id);
|
||||
$crc_sbas_coll = crc32($sbas_id . '_' . $coll_id);
|
||||
$crc_sbas_record = crc32($sbas_id . '_' . $record_id);
|
||||
$crc_type = crc32($type);
|
||||
|
||||
foreach ($index_ids as $index_id)
|
||||
{
|
||||
$cl->UpdateAttributes($index_id, array("status"), array($record_id => array($new_stat)), true);
|
||||
}
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function replace_in_metas($rt_id, $meta_id, $tag_id, $record_id, $sbas_id, $coll_id, $grouping, $type, $content, $business, DateTime $created)
|
||||
{
|
||||
$crc_sbas_tag = crc32($sbas_id . '_' . $tag_id);
|
||||
$crc_sbas_coll = crc32($sbas_id . '_' . $coll_id);
|
||||
$crc_sbas_record = crc32($sbas_id . '_' . $record_id);
|
||||
$crc_type = crc32($type);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
$sql = "REPLACE INTO " . $rt_id . " VALUES (
|
||||
$sql = "REPLACE INTO " . $rt_id . " VALUES (
|
||||
'" . (int) $meta_id . "'
|
||||
,'" . str_replace("'", "\'", $content) . "'
|
||||
,'" . (int) $tag_id . "'
|
||||
@@ -148,25 +138,25 @@ class sphinxrt
|
||||
," . (int) $business . "
|
||||
," . (int) crc32($coll_id . '_' . $business) . "
|
||||
," . (int) $created->format('U') . " )";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->closeCursor();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->connection->commit();
|
||||
$this->connection->commit();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function replace_in_documents($rt_id, $record_id, $value, $sbas_id, $coll_id, $grouping, $type, DateTime $created)
|
||||
{
|
||||
$crc_sbas_coll = crc32($sbas_id . '_' . $coll_id);
|
||||
$crc_sbas_record = crc32($sbas_id . '_' . $record_id);
|
||||
$crc_type = crc32($type);
|
||||
public function replace_in_documents($rt_id, $record_id, $value, $sbas_id, $coll_id, $grouping, $type, DateTime $created)
|
||||
{
|
||||
$crc_sbas_coll = crc32($sbas_id . '_' . $coll_id);
|
||||
$crc_sbas_record = crc32($sbas_id . '_' . $record_id);
|
||||
$crc_type = crc32($type);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
$sql = "REPLACE INTO " . $rt_id . " VALUES (
|
||||
$sql = "REPLACE INTO " . $rt_id . " VALUES (
|
||||
'" . (int) $record_id . "'
|
||||
,'" . str_replace("'", "\'", $value) . "'
|
||||
," . (int) $record_id . "
|
||||
@@ -179,13 +169,12 @@ class sphinxrt
|
||||
,0
|
||||
," . (int) $created->format('U') . " )";
|
||||
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $this;
|
||||
}
|
||||
$this->connection->commit();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user