From 281ca1edf588506d4c715f86f96709f7f0e232c0 Mon Sep 17 00:00:00 2001 From: "Johannes Tyra (BD)" Date: Mon, 24 Sep 2018 10:37:29 +0200 Subject: [PATCH 1/5] Changes for using memcached class (instad of old memcache) --- UPGRADE_TO_1_2 | 4 ++-- lib/Doctrine/Cache/Memcache.php | 35 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/UPGRADE_TO_1_2 b/UPGRADE_TO_1_2 index ef78cbbd8..74aa5c80e 100644 --- a/UPGRADE_TO_1_2 +++ b/UPGRADE_TO_1_2 @@ -812,7 +812,7 @@ fetching relationships. Now if we were to do the following PHP we'll get the SQL with an order by. [php] - $q = Doctrine::getTable('User') + $q = Doctrine_Core::getTable('User') ->createQuery('u') ->leftJoin('u.Articles a'); @@ -826,7 +826,7 @@ Now you should see this SQL query. Or if you lazily fetch the `Articles` they will be lazily loaded with the order by. [php] - $user = Doctrine::getTable('User')->find(1); + $user = Doctrine_Core::getTable('User')->find(1); $articles = $user->Articles; This would execute the following SQL query. diff --git a/lib/Doctrine/Cache/Memcache.php b/lib/Doctrine/Cache/Memcache.php index f366c204d..2edaad4c1 100644 --- a/lib/Doctrine/Cache/Memcache.php +++ b/lib/Doctrine/Cache/Memcache.php @@ -34,19 +34,19 @@ class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver { /** - * @var Memcache $_memcache memcache object + * @var Memcache $_memcached memcache object */ - protected $_memcache = null; + protected $_memcached = null; /** * constructor * * @param array $options associative array of cache driver options */ - public function __construct($options = array()) + public function __construct($options = array()) { - if ( ! extension_loaded('memcache')) { - throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.'); + if ( ! extension_loaded('memcached')) { + throw new Doctrine_Cache_Exception('In order to use Memcached driver, the memcached extension must be loaded.'); } parent::__construct($options); @@ -59,16 +59,13 @@ public function __construct($options = array()) $this->setOption('servers', $value); } - $this->_memcache = new Memcache; + $this->_memcached = new Memcached; foreach ($this->_options['servers'] as $server) { - if ( ! array_key_exists('persistent', $server)) { - $server['persistent'] = true; - } if ( ! array_key_exists('port', $server)) { $server['port'] = 11211; } - $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']); + $this->_memcached->addServer($server['host'], $server['port']); } } @@ -80,7 +77,7 @@ public function __construct($options = array()) */ protected function _doFetch($id, $testCacheValidity = true) { - return $this->_memcache->get($id); + return $this->_memcached->get($id); } /** @@ -91,7 +88,7 @@ protected function _doFetch($id, $testCacheValidity = true) */ protected function _doContains($id) { - return (bool) $this->_memcache->get($id); + return (bool) $this->_memcached->get($id); } /** @@ -105,13 +102,7 @@ protected function _doContains($id) */ protected function _doSave($id, $data, $lifeTime = false) { - if ($this->_options['compression']) { - $flag = MEMCACHE_COMPRESSED; - } else { - $flag = 0; - } - - return $this->_memcache->set($id, $data, $flag, $lifeTime); + return $this->_memcached->set($id, $data, $lifeTime); } /** @@ -123,7 +114,7 @@ protected function _doSave($id, $data, $lifeTime = false) */ protected function _doDelete($id) { - return $this->_memcache->delete($id); + return $this->_memcached->delete($id); } /** @@ -134,11 +125,11 @@ protected function _doDelete($id) protected function _getCacheKeys() { $keys = array(); - $allSlabs = $this->_memcache->getExtendedStats('slabs'); + $allSlabs = $this->_memcached->getExtendedStats('slabs'); foreach ($allSlabs as $server => $slabs) { foreach (array_keys($slabs) as $slabId) { - $dump = $this->_memcache->getExtendedStats('cachedump', (int) $slabId); + $dump = $this->_memcached->getExtendedStats('cachedump', (int) $slabId); foreach ($dump as $entries) { if ($entries) { $keys = array_merge($keys, array_keys($entries)); From 10d256a22b7afaacac1740e2cae7b11d93928b93 Mon Sep 17 00:00:00 2001 From: "Johannes Tyra (BD)" Date: Fri, 28 Sep 2018 11:21:23 +0200 Subject: [PATCH 2/5] Added Cache/Memcached.php (new memcache class) / Changes in Cache/Memcache.php (back compatibility) --- lib/Doctrine/Cache/Memcache.php | 24 +++--- lib/Doctrine/Cache/Memcached.php | 142 +++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 lib/Doctrine/Cache/Memcached.php diff --git a/lib/Doctrine/Cache/Memcache.php b/lib/Doctrine/Cache/Memcache.php index 2edaad4c1..ed34fe885 100644 --- a/lib/Doctrine/Cache/Memcache.php +++ b/lib/Doctrine/Cache/Memcache.php @@ -34,9 +34,9 @@ class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver { /** - * @var Memcache $_memcached memcache object + * @var Memcache $_memcache memcache object */ - protected $_memcached = null; + protected $_memcache = null; /** * constructor @@ -45,8 +45,8 @@ class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver */ public function __construct($options = array()) { - if ( ! extension_loaded('memcached')) { - throw new Doctrine_Cache_Exception('In order to use Memcached driver, the memcached extension must be loaded.'); + if ( ! extension_loaded('memcache')) { + throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.'); } parent::__construct($options); @@ -59,13 +59,13 @@ public function __construct($options = array()) $this->setOption('servers', $value); } - $this->_memcached = new Memcached; + $this->_memcache = new Memcached; foreach ($this->_options['servers'] as $server) { if ( ! array_key_exists('port', $server)) { $server['port'] = 11211; } - $this->_memcached->addServer($server['host'], $server['port']); + $this->_memcache->addServer($server['host'], $server['port']); } } @@ -77,7 +77,7 @@ public function __construct($options = array()) */ protected function _doFetch($id, $testCacheValidity = true) { - return $this->_memcached->get($id); + return $this->_memcache->get($id); } /** @@ -88,7 +88,7 @@ protected function _doFetch($id, $testCacheValidity = true) */ protected function _doContains($id) { - return (bool) $this->_memcached->get($id); + return (bool) $this->_memcache->get($id); } /** @@ -102,7 +102,7 @@ protected function _doContains($id) */ protected function _doSave($id, $data, $lifeTime = false) { - return $this->_memcached->set($id, $data, $lifeTime); + return $this->_memcache->set($id, $data, $lifeTime); } /** @@ -114,7 +114,7 @@ protected function _doSave($id, $data, $lifeTime = false) */ protected function _doDelete($id) { - return $this->_memcached->delete($id); + return $this->_memcache->delete($id); } /** @@ -125,11 +125,11 @@ protected function _doDelete($id) protected function _getCacheKeys() { $keys = array(); - $allSlabs = $this->_memcached->getExtendedStats('slabs'); + $allSlabs = $this->_memcache->getExtendedStats('slabs'); foreach ($allSlabs as $server => $slabs) { foreach (array_keys($slabs) as $slabId) { - $dump = $this->_memcached->getExtendedStats('cachedump', (int) $slabId); + $dump = $this->_memcache->getExtendedStats('cachedump', (int) $slabId); foreach ($dump as $entries) { if ($entries) { $keys = array_merge($keys, array_keys($entries)); diff --git a/lib/Doctrine/Cache/Memcached.php b/lib/Doctrine/Cache/Memcached.php new file mode 100644 index 000000000..9e823ef87 --- /dev/null +++ b/lib/Doctrine/Cache/Memcached.php @@ -0,0 +1,142 @@ +. + */ + +/** + * Memcached cache driver + * + * @package Doctrine + * @subpackage Cache + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 1.0 + * @version $Revision: 7490 $ + * @author Konsta Vesterinen + * @author Jonathan H. Wage + */ +class Doctrine_Cache_Memcached extends Doctrine_Cache_Driver +{ + /** + * @var Memcache $_memcached memcache object + */ + protected $_memcached = null; + + /** + * constructor + * + * @param array $options associative array of cache driver options + */ + public function __construct($options = array()) + { + if ( ! extension_loaded('memcached')) { + throw new Doctrine_Cache_Exception('In order to use Memcached driver, the memcached extension must be loaded.'); + } + parent::__construct($options); + + if (isset($options['servers'])) { + $value= $options['servers']; + if (isset($value['host'])) { + // in this case, $value seems to be a simple associative array (one server only) + $value = array(0 => $value); // let's transform it into a classical array of associative arrays + } + $this->setOption('servers', $value); + } + + $this->_memcached = new Memcached; + + foreach ($this->_options['servers'] as $server) { + if ( ! array_key_exists('port', $server)) { + $server['port'] = 11211; + } + $this->_memcached->addServer($server['host'], $server['port']); + } + } + + /** + * Test if a cache record exists for the passed id + * + * @param string $id cache id + * @return mixed Returns either the cached data or false + */ + protected function _doFetch($id, $testCacheValidity = true) + { + return $this->_memcached->get($id); + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record + */ + protected function _doContains($id) + { + return (bool) $this->_memcached->get($id); + } + + /** + * Save a cache record directly. This method is implemented by the cache + * drivers and used in Doctrine_Cache_Driver::save() + * + * @param string $id cache id + * @param string $data data to cache + * @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime) + * @return boolean true if no problem + */ + protected function _doSave($id, $data, $lifeTime = false) + { + return $this->_memcached->set($id, $data, $lifeTime); + } + + /** + * Remove a cache record directly. This method is implemented by the cache + * drivers and used in Doctrine_Cache_Driver::delete() + * + * @param string $id cache id + * @return boolean true if no problem + */ + protected function _doDelete($id) + { + return $this->_memcached->delete($id); + } + + /** + * Fetch an array of all keys stored in cache + * + * @return array Returns the array of cache keys + */ + protected function _getCacheKeys() + { + $keys = array(); + $allSlabs = $this->_memcached->getExtendedStats('slabs'); + + foreach ($allSlabs as $server => $slabs) { + foreach (array_keys($slabs) as $slabId) { + $dump = $this->_memcached->getExtendedStats('cachedump', (int) $slabId); + foreach ($dump as $entries) { + if ($entries) { + $keys = array_merge($keys, array_keys($entries)); + } + } + } + } + return $keys; + } +} \ No newline at end of file From 6fd45f605634f6d435a8acd60b30d23a035eade9 Mon Sep 17 00:00:00 2001 From: "Johannes Tyra (BD)" Date: Mon, 17 Dec 2018 14:33:54 +0100 Subject: [PATCH 3/5] CHANGE: Php 7.3 fix in Doctrine_Query_Tokenizer --- lib/Doctrine/Query/Tokenizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Query/Tokenizer.php b/lib/Doctrine/Query/Tokenizer.php index 402274132..aed58797d 100644 --- a/lib/Doctrine/Query/Tokenizer.php +++ b/lib/Doctrine/Query/Tokenizer.php @@ -93,7 +93,7 @@ public function tokenizeQuery($query) break; case 'by': - continue; + break; default: if ( ! isset($p)) { From c80b23db9b8655b5d7e36a69fa048138e0984b79 Mon Sep 17 00:00:00 2001 From: Johannes Tyra Date: Tue, 5 Feb 2019 11:02:09 +0100 Subject: [PATCH 4/5] CHANGE: Changes / FIx in setLastElement // RecordDriver --- lib/Doctrine/Hydrator/RecordDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php index b4944428b..bd60adf8f 100644 --- a/lib/Doctrine/Hydrator/RecordDriver.php +++ b/lib/Doctrine/Hydrator/RecordDriver.php @@ -106,7 +106,7 @@ public function setLastElement(&$prev, &$coll, $index, $dqlAlias, $oneToOne) return; } - if (count($coll) > 0) { + if (is_object($coll) && count($coll) > 0) { $prev[$dqlAlias] = $coll->getLast(); } } From aa43af5b5853c3ab07915f066fb36ff3dda967a2 Mon Sep 17 00:00:00 2001 From: Johannes Tyra Date: Mon, 16 Dec 2019 09:20:44 +0100 Subject: [PATCH 5/5] CHANGE: Small Change in comment --- lib/Doctrine/Table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 4cf111a0c..e4bf69ffb 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -31,8 +31,8 @@ * @version $Revision$ * @link www.doctrine-project.org * @since 1.0 - * @method mixed findBy*(mixed $value) magic finders; @see __call() - * @method mixed findOneBy*(mixed $value) magic finders; @see __call() + * method mixed findBy*(mixed $value) magic finders; @see __call() + * method mixed findOneBy*(mixed $value) magic finders; @see __call() */ class Doctrine_Table extends Doctrine_Configurable implements Countable, Serializable {