Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2014-08-04 20:12:20 +0400
committermattab <matthieu.aubry@gmail.com>2014-08-04 20:12:20 +0400
commite7c460432366f043b84c9f49fea40f528c769599 (patch)
tree6505eee00271cccbd8247198d4ee4061af37d93f /core/Plugin.php
parent34f27256917c427fd45cf7dcbbd84abe28914186 (diff)
Fixing issue when there is an invalid cache pointing to a file that does not exist anymore.
Should resolve error: `Warning: include_once(/home/piwik-demo2/www/plugins/ExamplePlugin/Columns/ExampleVisitDimension.php): failed to open stream: No such file or directory in /home/piwik-demo2/www/core/Plugin.php on line 356 `
Diffstat (limited to 'core/Plugin.php')
-rw-r--r--core/Plugin.php88
1 files changed, 58 insertions, 30 deletions
diff --git a/core/Plugin.php b/core/Plugin.php
index 389e85a6f6..3b3764818f 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -352,39 +352,14 @@ class Plugin
if ($this->cache->has()) {
$components = $this->cache->get();
- foreach ($components as $file => $klass) {
- include_once $file;
+ if($this->includeComponents($components)) {
+ return $components;
+ } else {
+ // problem including one cached file, refresh cache
}
-
- return $components;
}
- $components = array();
-
- $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/' . $this->pluginName .'/' . $directoryWithinPlugin, '*.php');
-
- foreach ($files as $file) {
- require_once $file;
-
- $fileName = basename($file, '.php');
- $klassName = sprintf('Piwik\\Plugins\\%s\\%s\\%s', $this->pluginName, $directoryWithinPlugin, $fileName);
-
- if (!class_exists($klassName)) {
- continue;
- }
-
- if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
- continue;
- }
-
- $klass = new \ReflectionClass($klassName);
-
- if ($klass->isAbstract()) {
- continue;
- }
-
- $components[$file] = $klassName;
- }
+ $components = $this->doFindMultipleComponents($directoryWithinPlugin, $expectedSubclass);
$this->cache->set($components);
@@ -455,4 +430,57 @@ class Plugin
return false;
}
}
+
+ /**
+ * @param $directoryWithinPlugin
+ * @param $expectedSubclass
+ * @return array
+ */
+ private function doFindMultipleComponents($directoryWithinPlugin, $expectedSubclass)
+ {
+ $components = array();
+
+ $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/' . $this->pluginName . '/' . $directoryWithinPlugin, '*.php');
+
+ foreach ($files as $file) {
+ require_once $file;
+
+ $fileName = basename($file, '.php');
+ $klassName = sprintf('Piwik\\Plugins\\%s\\%s\\%s', $this->pluginName, $directoryWithinPlugin, $fileName);
+
+ if (!class_exists($klassName)) {
+ continue;
+ }
+
+ if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
+ continue;
+ }
+
+ $klass = new \ReflectionClass($klassName);
+
+ if ($klass->isAbstract()) {
+ continue;
+ }
+
+ $components[$file] = $klassName;
+ }
+ return $components;
+ }
+
+ /**
+ * @param $components
+ * @return bool true if all files were included, false if any file cannot be read
+ */
+ private function includeComponents($components)
+ {
+ foreach ($components as $file => $klass) {
+ if (!is_readable($file)) {
+ return false;
+ }
+ }
+ foreach ($components as $file => $klass) {
+ include_once $file;
+ }
+ return true;
+ }
}