import v2.0.0.0_RC3 | 2012-07-01

https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
2019-07-17 22:31:04 +02:00
parent 38c146901c
commit 2f397f01f7
2677 changed files with 296182 additions and 45159 deletions

View File

@ -17,7 +17,7 @@
* @subpackage Adapter
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Db.php 17217 2009-07-28 02:02:37Z matthew $
* @version $Id: Db.php 18705 2009-10-26 13:05:13Z matthew $
*/
/**
@ -66,6 +66,11 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
*/
protected $_messageTable = null;
/**
* @var Zend_Db_Table_Row_Abstract
*/
protected $_messageRow = null;
/**
* Constructor
*
@ -87,6 +92,33 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
throw new Zend_Queue_Exception('Options array item: Zend_Db_Select::FOR_UPDATE must be boolean');
}
if (isset($this->_options['dbAdapter'])
&& $this->_options['dbAdapter'] instanceof Zend_Db_Adapter_Abstract) {
$db = $this->_options['dbAdapter'];
} else {
$db = $this->_initDbAdapter();
}
$this->_queueTable = new Zend_Queue_Adapter_Db_Queue(array(
'db' => $db,
));
$this->_messageTable = new Zend_Queue_Adapter_Db_Message(array(
'db' => $db,
));
}
/**
* Initialize Db adapter using 'driverOptions' section of the _options array
*
* Throws an exception if the adapter cannot connect to DB.
*
* @return Zend_Db_Adapter_Abstract
* @throws Zend_Queue_Exception
*/
protected function _initDbAdapter()
{
$options = &$this->_options['driverOptions'];
if (!array_key_exists('type', $options)) {
require_once 'Zend/Queue/Exception.php';
@ -113,20 +145,17 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
throw new Zend_Queue_Exception("Configuration array must have a key for 'dbname' for the database to use");
}
$type = $options['type'];
unset($options['type']);
try {
$db = Zend_Db::factory($options['type'], $options);
$this->_queueTable = new Zend_Queue_Adapter_Db_Queue(array(
'db' => $db,
));
$this->_messageTable = new Zend_Queue_Adapter_Db_Message(array(
'db' => $db,
));
$db = Zend_Db::factory($type, $options);
} catch (Zend_Db_Exception $e) {
require_once 'Zend/Queue/Exception.php';
throw new Zend_Queue_Exception('Error connecting to database: ' . $e->getMessage(), $e->getCode());
}
return $db;
}
/********************************************************************
@ -146,7 +175,15 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
*/
public function isExists($name)
{
return in_array($name, $this->getQueues());
$id = 0;
try {
$id = $this->getQueueId($name);
} catch (Zend_Queue_Exception $e) {
return false;
}
return ($id > 0);
}
/**
@ -170,10 +207,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
$queue = $this->_queueTable->createRow();
$queue->queue_name = $name;
$queue->timeout = ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int)$timeout;
$queue->timeout = ($timeout === null) ? self::CREATE_TIMEOUT_DEFAULT : (int)$timeout;
try {
if ($id = $queue->save()) {
if ($queue->save()) {
return true;
}
} catch (Exception $e) {
@ -213,6 +250,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
}
}
if (array_key_exists($name, $this->_queues)) {
unset($this->_queues[$name]);
}
return true;
}
@ -230,11 +271,13 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
$query = $this->_queueTable->select();
$query->from($this->_queueTable, array('queue_id', 'queue_name'));
$list = array();
$this->_queues = array();
foreach ($this->_queueTable->fetchAll($query) as $queue) {
$list[] = $queue->queue_name;
$this->_queues[$queue->queue_name] = (int)$queue->queue_id;
}
$list = array_keys($this->_queues);
return $list;
}
@ -275,6 +318,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
*/
public function send($message, Zend_Queue $queue = null)
{
if ($this->_messageRow === null) {
$this->_messageRow = $this->_messageTable->createRow();
}
if ($queue === null) {
$queue = $this->_queue;
}
@ -291,7 +338,7 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
throw new Zend_Queue_Exception('Queue does not exist:' . $queue->getName());
}
$msg = $this->_messageTable->createRow();
$msg = clone $this->_messageRow;
$msg->queue_id = $this->getQueueId($queue->getName());
$msg->created = time();
$msg->body = $message;
@ -346,41 +393,43 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
// start transaction handling
try {
$db->beginTransaction();
if ( $maxMessages > 0 ) { // ZF-7666 LIMIT 0 clause not included.
$db->beginTransaction();
$query = $db->select();
if ($this->_config['options'][Zend_Db_Select::FOR_UPDATE]) {
// turn on forUpdate
$query->forUpdate();
}
$query->from($info['name'], array('*'))
->where('queue_id=?', $this->getQueueId($queue->getName()))
->where('handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime)
->limit($maxMessages);
foreach ($db->fetchAll($query) as $data) {
// setup our changes to the message
$data['handle'] = md5(uniqid(rand(), true));
$update = array(
'handle' => $data['handle'],
'timeout' => $microtime,
);
// update the database
$where = array();
$where[] = $db->quoteInto('message_id=?', $data['message_id']);
$where[] = 'handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime;
$count = $db->update($info['name'], $update, $where);
// we check count to make sure no other thread has gotten
// the rows after our select, but before our update.
if ($count > 0) {
$msgs[] = $data;
$query = $db->select();
if ($this->_options['options'][Zend_Db_Select::FOR_UPDATE]) {
// turn on forUpdate
$query->forUpdate();
}
$query->from($info['name'], array('*'))
->where('queue_id=?', $this->getQueueId($queue->getName()))
->where('handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime)
->limit($maxMessages);
foreach ($db->fetchAll($query) as $data) {
// setup our changes to the message
$data['handle'] = md5(uniqid(rand(), true));
$update = array(
'handle' => $data['handle'],
'timeout' => $microtime,
);
// update the database
$where = array();
$where[] = $db->quoteInto('message_id=?', $data['message_id']);
$where[] = 'handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime;
$count = $db->update($info['name'], $update, $where);
// we check count to make sure no other thread has gotten
// the rows after our select, but before our update.
if ($count > 0) {
$msgs[] = $data;
}
}
$db->commit();
}
$db->commit();
} catch (Exception $e) {
$db->rollBack();
@ -465,6 +514,10 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
*/
protected function getQueueId($name)
{
if (array_key_exists($name, $this->_queues)) {
return $this->_queues[$name];
}
$query = $this->_queueTable->select();
$query->from($this->_queueTable, array('queue_id'))
->where('queue_name=?', $name);
@ -476,6 +529,8 @@ class Zend_Queue_Adapter_Db extends Zend_Queue_Adapter_AdapterAbstract
throw new Zend_Queue_Exception('Queue does not exist: ' . $name);
}
return (int)$queue->queue_id;
$this->_queues[$name] = (int)$queue->queue_id;
return $this->_queues[$name];
}
}