Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/6049' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 14, 2014
158 parents 11956fb + 296d83f + 38f33dd + 87e41f1 + adf2b3d + 756d5d5 + 40e1948 + fae5b14 + 1d8b0d4 + 0885ee4 + 31378a4 + 22dc55a + 4fe9653 + 0835021 + 26ee41a + be4158f + a1e2d7e + 4abdf38 + e59ea5a + fbff658 + 48d0341 + 401d180 + 4e95264 + 5431207 + a7a7974 + 7c3f597 + a50748b + 700cf3a + 1582c31 + 016f50c + 9852497 + 073b126 + bd99c5c + 56451bd + 8fe4cad + 18812d8 + 89590ab + 0f8f25b + c2a03a9 + 4c690cd + 52cb4e6 + f7ed984 + 1d190a2 + 3c5d19b + c3c849d + faa6e57 + ad46181 + 12a401e + 3738445 + 65aacba + bf5f5a3 + c2ac9c0 + 6d7cf99 + 1841b47 + f81171b + 5ffaadf + cd6d5f2 + a512601 + 926e71f + 1f29b3e + a75171a + 9a8e72f + 814716e + 88d9371 + 678232d + a0560e8 + 4ff045c + ac805a6 + 41f360c + 1939a3c + 730da5d + dd0a1b5 + 1bc1ed5 + cea3413 + f2b47df + 2b8aa6a + 42cb3fe + 46afe3b + ef4289e + f40a98a + 8c27e9d + 512d6ca + b1452f8 + 9f6e228 + cf96a5a + aa9ef86 + 04be01e + 93487ba + c640cb5 + ab2b436 + a876e82 + 01f54c9 + f0abecc + 920eae1 + db4f625 + f51678c + 5975f0e + e9d78fe + 03de5ee + d7320d7 + 16ff5c5 + f170b61 + b506606 + f6c7309 + 675c421 + 43220df + c076d41 + e9406c0 + bb1710e + 565433c + be0baa3 + 8d2dae7 + ba17210 + bf83129 + 40926a2 + a7690f0 + 4fbd64e + f1f095f + 5077dc6 + 7d6f60c + a5f3296 + e036825 + 337996c + 285fc46 + 277a8aa + 0103b22 + 0d32a70 + bb27ee5 + e8ecd1e + f2b29a0 + 5205046 + 257c166 + 3122c56 + a8eef4b + 736bf24 + f1bdd85 + 30d927d + 0b20126 + ef5cf6f + 2efe2a7 + 9c5c0a0 + b163911 + 078c1c8 + ae78853 + 4290f30 + 77fe406 + 54f7675 + a3a2c69 + 7bf23e4 + 45a20bc + 6bd2e48 + 7762647 + bf16f63 + d4e61ff + 9969a8b + b3e0a07 + c5055d9 + 6a91c34 commit 3bcbe8e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Zend\Cache\Storage\TaggableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Stdlib\ErrorHandler;
use ArrayObject;

class Filesystem extends AbstractAdapter implements
AvailableSpaceCapableInterface,
Expand Down Expand Up @@ -131,6 +132,8 @@ public function flush()
* Remove expired items
*
* @return bool
*
* @triggers clearExpired.exception(ExceptionEvent)
*/
public function clearExpired()
{
Expand Down Expand Up @@ -161,7 +164,13 @@ public function clearExpired()
}
$error = ErrorHandler::stop();
if ($error) {
throw new Exception\RuntimeException("Failed to clear expired items", 0, $error);
$result = false;
return $this->triggerException(
__FUNCTION__,
new ArrayObject(),
$result,
new Exception\RuntimeException('Failed to clear expired items', 0, $error)
);
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/Plugin/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function attach(EventManagerInterface $events, $priority = 1)

$this->listeners[] = $events->attach('decrementItem.exception', $callback, $priority);
$this->listeners[] = $events->attach('decrementItems.exception', $callback, $priority);

// utility
$this->listeners[] = $events->attach('clearExpired.exception', $callback, $priority);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/Storage/Adapter/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace ZendTest\Cache\Storage\Adapter;

use Zend\Cache;
use Zend\Cache\Storage\Plugin\ExceptionHandler;
use Zend\Cache\Storage\Plugin\PluginOptions;

/**
* @group Zend_Cache
Expand Down Expand Up @@ -281,4 +283,22 @@ public function testGetMetadataWithAtime()
$expectedAtime = fileatime($meta['filespec'] . '.dat');
$this->assertEquals($expectedAtime, $meta['atime']);
}

public function testClearExpiredExceptionTriggersEvent()
{
$this->_options->setTtl(0.1);
$this->_storage->setItem('k', 'v');
$dirs = glob($this->_tmpCacheDir . '/*');
if (count($dirs) === 0) {
$this->fail('Could not find cache dir');
}
chmod($dirs[0], 0500); //make directory rx, unlink should fail
sleep(1); //wait for the entry to expire
$plugin = new ExceptionHandler();
$options = new PluginOptions(array('throw_exceptions' => false));
$plugin->setOptions($options);
$this->_storage->addPlugin($plugin);
$this->_storage->clearExpired();
chmod($dirs[0], 0700); //set dir back to writable for tearDown
}
}
2 changes: 2 additions & 0 deletions test/Storage/Plugin/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function testAddPlugin()

'decrementItem.exception' => 'onException',
'decrementItems.exception' => 'onException',

'clearExpired.exception' => 'onException',
);
foreach ($expectedListeners as $eventName => $expectedCallbackMethod) {
$listeners = $this->_adapter->getEventManager()->getListeners($eventName);
Expand Down

0 comments on commit 3bcbe8e

Please sign in to comment.