From 8f17e2b17878901169fc5a9387334f51a2987d71 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 14:48:53 +0200 Subject: [PATCH 01/11] Add package config params and element helper description + events for the plugin --- .../elements/plugins/plugin.elementhelper.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 38ff25c..780cb5c 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -1,5 +1,15 @@ Date: Sat, 13 Sep 2014 14:49:31 +0200 Subject: [PATCH 02/11] Clean up cache options configuration --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 780cb5c..27dd3bb 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -21,8 +21,8 @@ } // Set up native modx caching -$cacheid = isset($settings['cacheid']) ? $settings['cacheid'] : $packagename; -$cachetime = isset($settings['cachetime']) ? $settings['cachetime'] : 0; +$cacheid = $packagename; +$cachetime = 0; $cacheoptions = array( // Specify folder/partition inside the modx cache folder where cache files get saved in xPDO::OPT_CACHE_KEY => $packagename From 3915cdb75b84ebceb86eadf9097a7de11de66f51 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 14:50:31 +0200 Subject: [PATCH 03/11] Improve fallback for elementhelper.usergroups system setting by setting Administrator user group by default --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 27dd3bb..5ff3df5 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -29,8 +29,8 @@ ); // Get the usergroups where ElementHelper should be active -// (usually only Administrators/Devs that can change files in the target directories) -$usergroups = explode(',', $modx->getOption('elementhelper.usergroups')); +// by default only members of the Administrator user group +$usergroups = explode(',', $modx->getOption('elementhelper.usergroups'), null, 'Administrator'); if ($modx->user->isMember($usergroups)) { From bb03073d0204b252cf334f688810a2266c06d170 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 15:01:21 +0200 Subject: [PATCH 04/11] Improve class/service loading and error message on failure --- .../elements/plugins/plugin.elementhelper.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 5ff3df5..9b2dc0e 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -8,8 +8,8 @@ $classname = 'ElementHelper'; // set up basic paths -$packagepath = MODX_CORE_PATH . 'components/' . $packagename . '/'; -$modelpath = $packagepath . 'model/'; +$packagepath = $modx->getOption('elementhelper.core_path', null, MODX_CORE_PATH . 'components/' . $packagename . '/'); +$classpath = $packagepath . 'model/' . $packagename . '/'; // Turn debug messages on/off $debug = false; @@ -28,16 +28,15 @@ xPDO::OPT_CACHE_KEY => $packagename ); +// Initialize the class +$element_helper = $modx->getService($packagename, $classname, $classpath); + // Get the usergroups where ElementHelper should be active // by default only members of the Administrator user group $usergroups = explode(',', $modx->getOption('elementhelper.usergroups'), null, 'Administrator'); -if ($modx->user->isMember($usergroups)) +if ($modx->user->isMember($usergroups) && $element_helper instanceof $classname) { - $default_element_helper_core_path = $modx->getOption('core_path') . 'components/elementhelper/'; - $element_helper_core_path = $modx->getOption('elementhelper.core_path', null, $default_element_helper_core_path); - - $element_helper = $modx->getService($packagename, 'ElementHelper', $element_helper_core_path . 'model/elementhelper/'); $element_types = array( 'templates' => array( @@ -310,4 +309,6 @@ function get_files($directory_path, $modx) // Set logLevel back to ERROR, preventing a lot of crap getting logged $modx->setLogLevel(modX::LOG_LEVEL_ERROR); } +} else if (!($element_helper instanceof $classname)) { + $modx->log(modX::LOG_LEVEL_ERROR, '[' . $classname . ' Plugin] Could not instantiate class ' . $classname . ' from ' . $classpath); } \ No newline at end of file From a29b28a1f096f92982373b0ffd1e05d3d0030d5a Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 15:29:11 +0200 Subject: [PATCH 05/11] Change plugin workflow for system events to switch statement, better code readability like that + catching wrong system events --- .../elements/plugins/plugin.elementhelper.php | 427 +++++++++--------- 1 file changed, 219 insertions(+), 208 deletions(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 9b2dc0e..bf4fed7 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -37,268 +37,278 @@ if ($modx->user->isMember($usergroups) && $element_helper instanceof $classname) { - - $element_types = array( - 'templates' => array( - 'class_name' => 'modTemplate', - 'path' => $modx->getOption('elementhelper.template_path', null, 'core/elements/templates/') - ), - - 'chunks' => array( - 'class_name' => 'modChunk', - 'path' => $modx->getOption('elementhelper.chunk_path', null, 'core/elements/chunks/') - ), - - 'snippets' => array( - 'class_name' => 'modSnippet', - 'path' => $modx->getOption('elementhelper.snippet_path', null, 'core/elements/snippets/') - ), - - 'plugins' => array( - 'class_name' => 'modPlugin', - 'path' => $modx->getOption('elementhelper.plugin_path', null, 'core/elements/plugins/') - ) - ); - - $element_history = unserialize($modx->getOption('elementhelper.element_history')); - - // Get the files from the directory and all sub directories - function get_files($directory_path, $modx) + switch($modx->event->name) { - $file_list = array(); - - if (is_dir($directory_path)) - { - $directory = opendir($directory_path); + case 'OnSiteRefresh': + break; + + case 'OnManagerPageInit': + case 'OnWebPageInit': + $element_types = array( + 'templates' => array( + 'class_name' => 'modTemplate', + 'path' => $modx->getOption('elementhelper.template_path', null, 'core/elements/templates/') + ), + + 'chunks' => array( + 'class_name' => 'modChunk', + 'path' => $modx->getOption('elementhelper.chunk_path', null, 'core/elements/chunks/') + ), + + 'snippets' => array( + 'class_name' => 'modSnippet', + 'path' => $modx->getOption('elementhelper.snippet_path', null, 'core/elements/snippets/') + ), + + 'plugins' => array( + 'class_name' => 'modPlugin', + 'path' => $modx->getOption('elementhelper.plugin_path', null, 'core/elements/plugins/') + ) + ); + + $element_history = unserialize($modx->getOption('elementhelper.element_history')); + + // Get the files from the directory and all sub directories + function get_files($directory_path, $modx) + { + $file_list = array(); - // Get a list of files from the element types directory - while (($item = readdir($directory)) !== false) - { - if ($item !== '.' && $item !== '..' && $item != '.DS_Store') + if (is_dir($directory_path)) { - $item_path = $directory_path . $item; + $directory = opendir($directory_path); - if (is_file($item_path)) - { - $file_list[] = $item_path; - } - else - { - $file_list = array_merge(get_files($item_path . '/', $modx), $file_list); + // Get a list of files from the element types directory + while (($item = readdir($directory)) !== false) + { + if ($item !== '.' && $item !== '..' && $item != '.DS_Store') + { + $item_path = $directory_path . $item; + + if (is_file($item_path)) + { + $file_list[] = $item_path; + } + else + { + $file_list = array_merge(get_files($item_path . '/', $modx), $file_list); + } + } } - } - } - closedir($directory); - } + closedir($directory); + } - return $file_list; - } + return $file_list; + } - // Create all the templates, snippets, chunks and plugins - foreach ($element_types as $element_type) - { - $log_prefix = '[' . $packagename . '] ' . $element_type['class_name'] . ': '; + // Create all the templates, snippets, chunks and plugins + foreach ($element_types as $element_type) + { + $log_prefix = '[' . $packagename . '] ' . $element_type['class_name'] . ': '; - $file_list = get_files(MODX_BASE_PATH . $element_type['path'], $modx); - $file_name = array(); + $file_list = get_files(MODX_BASE_PATH . $element_type['path'], $modx); + $file_name = array(); - // Stores the time the file was modified at - $modified = array(); + // Stores the time the file was modified at + $modified = array(); - // Go through all files in $file_list - foreach ($file_list as $file) { - $file_type = explode('.', $file); - $file_type = '.' . end($file_type); - $file_name = basename($file, $file_type); + // Go through all files in $file_list + foreach ($file_list as $file) + { + $file_type = explode('.', $file); + $file_type = '.' . end($file_type); + $file_name = basename($file, $file_type); - $file_names[] = $file_name; + $file_names[] = $file_name; - // should prevent problems when files have the same timestamp and would have the - // same array key... just adding a small random number of seconds to the filetime - if (array_key_exists(filemtime($file), $file_list)) - { - if (touch($file, filemtime($file) + mt_rand(1, 100))) - { - $modified[] = filemtime($file); + // should prevent problems when files have the same timestamp and would have the + // same array key... just adding a small random number of seconds to the filetime + if (array_key_exists(filemtime($file), $file_list)) + { + if (touch($file, filemtime($file) + mt_rand(1, 100))) + { + $modified[] = filemtime($file); + } + } + else + { + $modified[] = filemtime($file); + } } - } - else - { - $modified[] = filemtime($file); - } - } - - if ( ! empty($file_list)) - { - // Set the modified file times as the keys for the files - $file_list = array_combine($modified, $file_list); - // Sort the $files array backwards with key = timestamp of last modified - krsort($file_list); + if ( ! empty($file_list)) + { + // Set the modified file times as the keys for the files + $file_list = array_combine($modified, $file_list); - // Cut the array at first item = most recently modified file - $last_mod = key(array_slice($file_list, 0, 1, true)); + // Sort the $files array backwards with key = timestamp of last modified + krsort($file_list); - // Remove elements that are in the element history but no longer exist in the elements dir - if ($modx->getOption('elementhelper.auto_remove_elements', null, true)) - { - $element_type_name = $element_type['class_name']; + // Cut the array at first item = most recently modified file + $last_mod = key(array_slice($file_list, 0, 1, true)); - // Check if a history for this element type exists - if (isset($element_history[$element_type_name])) - { - // Loop through the element history for this element type - foreach ($element_history[$element_type_name] as $old_element_name) + // Remove elements that are in the element history but no longer exist in the elements dir + if ($modx->getOption('elementhelper.auto_remove_elements', null, true)) { - // Remove the element if it's not in the list of files - if (! in_array($old_element_name, $file_names)) + $element_type_name = $element_type['class_name']; + + // Check if a history for this element type exists + if (isset($element_history[$element_type_name])) { - $name_field = ($element_type_name === 'modTemplate' ? 'templatename' : 'name'); + // Loop through the element history for this element type + foreach ($element_history[$element_type_name] as $old_element_name) + { + // Remove the element if it's not in the list of files + if (! in_array($old_element_name, $file_names)) + { + $name_field = ($element_type_name === 'modTemplate' ? 'templatename' : 'name'); - $element = $modx->getObject($element_type_name, array($name_field => $old_element_name)); + $element = $modx->getObject($element_type_name, array($name_field => $old_element_name)); - $element->remove(); + $element->remove(); + } + } } } - } - } - // Save the list of created elements - $element_history_setting = $modx->getObject('modSystemSetting', 'elementhelper.element_history'); - $element_history_setting->set('value', serialize($element_helper->history)); - $element_history_setting->save(); + // Save the list of created elements + $element_history_setting = $modx->getObject('modSystemSetting', 'elementhelper.element_history'); + $element_history_setting->set('value', serialize($element_helper->history)); + $element_history_setting->save(); - // Check if cachefile exists / should be renewed / or cached if not there already - if (is_null($modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions)) || $modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions) !== $last_mod) - { - // Cache the newest filetime for that element class - $modx->cacheManager->set($cacheid . '.' . $element_type['class_name'], $last_mod, $cachetime, $cacheoptions); + // Check if cachefile exists / should be renewed / or cached if not there already + if (is_null($modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions)) || $modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions) !== $last_mod) + { + // Cache the newest filetime for that element class + $modx->cacheManager->set($cacheid . '.' . $element_type['class_name'], $last_mod, $cachetime, $cacheoptions); - $file_names = array(); + $file_names = array(); - foreach ($file_list as $file) - { - $file_type = explode('.', $file); - $file_type = '.' . end($file_type); - $file_name = basename($file, $file_type); + foreach ($file_list as $file) + { + $file_type = explode('.', $file); + $file_type = '.' . end($file_type); + $file_name = basename($file, $file_type); - $file_names[] = $file_name; + $file_names[] = $file_name; - $category_path = dirname(str_replace(MODX_BASE_PATH . $element_type['path'], '', $file)); - $category_names = explode('/', $category_path); + $category_path = dirname(str_replace(MODX_BASE_PATH . $element_type['path'], '', $file)); + $category_names = explode('/', $category_path); - // If it's not the current directory - if ($category_path !== '.') - { - foreach ($category_names as $i => $category_name) - { - $parent_id = $i !== 0 ? $element_helper->get_category_id($category_names[$i - 1]) : 0; + // If it's not the current directory + if ($category_path !== '.') + { + foreach ($category_names as $i => $category_name) + { + $parent_id = $i !== 0 ? $element_helper->get_category_id($category_names[$i - 1]) : 0; - $element_helper->create_category($category_name, $parent_id); - } - } + $element_helper->create_category($category_name, $parent_id); + } + } - $element_helper->create_element($element_type, $file, $file_type, $file_name); - } + $element_helper->create_element($element_type, $file, $file_type, $file_name); + } - // Refresh the cache - $modx->cacheManager->refresh(array( - 'resource' => array() - )); + // Refresh the cache + $modx->cacheManager->refresh(array( + 'resource' => array() + )); - if ($debug) - { - $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'updated and cache refreshed!'); - } - } - else - { - if ($debug) - { - $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'nothing changed! Last mod: ' . strftime('%d.%m.%Y %H:%M:%S', $modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions))); + if ($debug) + { + $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'updated and cache refreshed!'); + } + } + else + { + if ($debug) + { + $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'nothing changed! Last mod: ' . strftime('%d.%m.%Y %H:%M:%S', $modx->cacheManager->get($cacheid . '.' . $element_type['class_name'], $cacheoptions))); + } + } } } - } - } - $tv_json_path = MODX_BASE_PATH . $modx->getOption('elementhelper.tv_json_path', null, 'core/elements/template_variables.json'); + $tv_json_path = MODX_BASE_PATH . $modx->getOption('elementhelper.tv_json_path', null, 'core/elements/template_variables.json'); - // Get the template variables - if (file_exists($tv_json_path)) - { - $log_prefix = '[' . $packagename . '] modTemplateVar: '; - - $tv_json = file_get_contents($tv_json_path); - $tvs = ($tv_json === '' ? json_decode('[]') : json_decode($tv_json)); - $tv_names = array(); - $last_mod = filemtime($tv_json_path); + // Get the template variables + if (file_exists($tv_json_path)) + { + $log_prefix = '[' . $packagename . '] modTemplateVar: '; - // Check if cachefile exists / should be renewed / or cached if not there already - if (is_null($modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions)) || $modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions) !== $last_mod) - { - // Cache last mod time - $modx->cacheManager->set($cacheid . '.modTemplateVar', $last_mod, $cachetime, $cacheoptions); + $tv_json = file_get_contents($tv_json_path); + $tvs = ($tv_json === '' ? json_decode('[]') : json_decode($tv_json)); + $tv_names = array(); + $last_mod = filemtime($tv_json_path); - // Check if there are some TVs to loop through - if ($tvs !== null) - { - // Create all the template variables - foreach ($tvs as $tv) + // Check if cachefile exists / should be renewed / or cached if not there already + if (is_null($modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions)) || $modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions) !== $last_mod) { - $tv_names[] = $tv->name; + // Cache last mod time + $modx->cacheManager->set($cacheid . '.modTemplateVar', $last_mod, $cachetime, $cacheoptions); - if (isset($tv->category)) + // Check if there are some TVs to loop through + if ($tvs !== null) { - $element_helper->create_category($tv->category, 0); - } + // Create all the template variables + foreach ($tvs as $tv) + { + $tv_names[] = $tv->name; - $element_helper->create_tv($tv); - } + if (isset($tv->category)) + { + $element_helper->create_category($tv->category, 0); + } - // Remove elements that are in the element history but no longer exist in the TV JSON file - if ($modx->getOption('elementhelper.auto_remove_elements', null, true)) - { - // Check if a history for this element type exists - if (isset($element_history['modTemplateVar'])) - { - // Loop through the element history for this element type - foreach ($element_history['modTemplateVar'] as $old_element_name) + $element_helper->create_tv($tv); + } + + // Remove elements that are in the element history but no longer exist in the TV JSON file + if ($modx->getOption('elementhelper.auto_remove_elements', null, true)) { - // Remove the element if it's not in the list of files - if (! in_array($old_element_name, $tv_names)) + // Check if a history for this element type exists + if (isset($element_history['modTemplateVar'])) { - $element = $modx->getObject('modTemplateVar', array('name' => $old_element_name)); - - $element->remove(); + // Loop through the element history for this element type + foreach ($element_history['modTemplateVar'] as $old_element_name) + { + // Remove the element if it's not in the list of files + if (! in_array($old_element_name, $tv_names)) + { + $element = $modx->getObject('modTemplateVar', array('name' => $old_element_name)); + + $element->remove(); + } + } } } } - } - } - // Save the list of created elements - $element_history_setting = $modx->getObject('modSystemSetting', 'elementhelper.element_history'); - $element_history_setting->set('value', serialize($element_helper->history)); - $element_history_setting->save(); + // Save the list of created elements + $element_history_setting = $modx->getObject('modSystemSetting', 'elementhelper.element_history'); + $element_history_setting->set('value', serialize($element_helper->history)); + $element_history_setting->save(); - // Refresh the cache - $modx->cacheManager->refresh(array( - 'resource' => array() - )); + // Refresh the cache + $modx->cacheManager->refresh(array( + 'resource' => array() + )); - if ($debug) - { - $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'updated and cache refreshed!'); - } - } - else - { - if ($debug) - { - $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'nothing changed! Last mod: ' . strftime('%d.%m.%Y %H:%M:%S', $modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions))); + if ($debug) + { + $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'updated and cache refreshed!'); + } + } + else + { + if ($debug) + { + $modx->log(modX::LOG_LEVEL_INFO, $log_prefix . 'nothing changed! Last mod: ' . strftime('%d.%m.%Y %H:%M:%S', $modx->cacheManager->get($cacheid . '.modTemplateVar', $cacheoptions))); + } + } } - } + case 'default': + $modx->log(modX::LOG_LEVEL_ERROR, '[' . $classname . ' Plugin] Called on non-default system event ' . $modx->event->name); } if ($debug) @@ -309,6 +319,7 @@ function get_files($directory_path, $modx) // Set logLevel back to ERROR, preventing a lot of crap getting logged $modx->setLogLevel(modX::LOG_LEVEL_ERROR); } -} else if (!($element_helper instanceof $classname)) { +} else if (!($element_helper instanceof $classname)) +{ $modx->log(modX::LOG_LEVEL_ERROR, '[' . $classname . ' Plugin] Could not instantiate class ' . $classname . ' from ' . $classpath); } \ No newline at end of file From 700c6f1480f51e8d5ce37dfdbeb6bb8a2b06d2f5 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 15:33:26 +0200 Subject: [PATCH 06/11] Prepare for improved cache handling when the cache is cleared manually (OnSiteRefresh event) --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index bf4fed7..ea0f044 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -40,6 +40,10 @@ switch($modx->event->name) { case 'OnSiteRefresh': + // system event OnSiteRefresh triggered, deleting elementhelper cache partition + $modx->cacheManager->clean($cacheoptions); + // log to the console + $modx->log(modX::LOG_LEVEL_INFO, '[' . $classname . '] Cache files deleted!'); break; case 'OnManagerPageInit': From e6c57ee6380456e65b4e893a39d099ff64b1ac56 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 15:36:30 +0200 Subject: [PATCH 07/11] Add plugin to OnSiteRefresh system event in build script --- _build/data/transport.pluginevents.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_build/data/transport.pluginevents.php b/_build/data/transport.pluginevents.php index f6f3460..de9a26a 100644 --- a/_build/data/transport.pluginevents.php +++ b/_build/data/transport.pluginevents.php @@ -12,4 +12,9 @@ $events[2]->set('priority', 0); $events[2]->set('propertyset', 0); +$events[3] = $modx->newObject('modPluginEvent'); +$events[3]->set('event', 'OnSiteRefresh'); +$events[3]->set('priority', 0); +$events[3]->set('propertyset', 0); + return $events; \ No newline at end of file From 762218f38e5a684cd23995df35751a0acea8ec58 Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 15:40:21 +0200 Subject: [PATCH 08/11] Update changelog --- core/components/elementhelper/docs/changelog.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/components/elementhelper/docs/changelog.txt b/core/components/elementhelper/docs/changelog.txt index 7183cee..1243e81 100644 --- a/core/components/elementhelper/docs/changelog.txt +++ b/core/components/elementhelper/docs/changelog.txt @@ -1,3 +1,6 @@ +- (exside) ElementHelper cache files are now cleared when the site cache is manually emptied (by a member of an authorized user group) + + Element Helper 1.3.3 ==================================== - (JayCarney) Input properties fix From 73be0a1f34b886fff2feec593a23e8bec946b95a Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 17:19:37 +0200 Subject: [PATCH 09/11] Fix bugs introduced with changes --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index ea0f044..86cbe46 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -33,7 +33,7 @@ // Get the usergroups where ElementHelper should be active // by default only members of the Administrator user group -$usergroups = explode(',', $modx->getOption('elementhelper.usergroups'), null, 'Administrator'); +$usergroups = explode(',', $modx->getOption('elementhelper.usergroups', null, 'Administrator')); if ($modx->user->isMember($usergroups) && $element_helper instanceof $classname) { @@ -311,6 +311,8 @@ function get_files($directory_path, $modx) } } } + + break; case 'default': $modx->log(modX::LOG_LEVEL_ERROR, '[' . $classname . ' Plugin] Called on non-default system event ' . $modx->event->name); } From d216ebb140d644755c14a207d58a94a44009ad7a Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 17:23:06 +0200 Subject: [PATCH 10/11] Small changes to the Timing debug message and handling --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 86cbe46..7d2fcba 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -17,7 +17,7 @@ if ($debug) { $modx->setLogLevel(modX::LOG_LEVEL_INFO); - $timestart = $modx->getMicroTime(); + $tstart = microtime(true); } // Set up native modx caching @@ -319,8 +319,7 @@ function get_files($directory_path, $modx) if ($debug) { - $timeend = $modx->getMicroTime(); - $modx->log(modX::LOG_LEVEL_INFO, '{modPlugin}: ' . $packagename . ' executed in ' . sprintf('%2.4f s', $timeend - $timestart)); + $modx->log(modX::LOG_LEVEL_INFO, '[modPlugin]: ' . $classname . ' executed in ' . sprintf('%2.4f s', microtime(true) - $tstart)); // Set logLevel back to ERROR, preventing a lot of crap getting logged $modx->setLogLevel(modX::LOG_LEVEL_ERROR); From 9cede01a123c47648ff375be70d084b97ae76cfd Mon Sep 17 00:00:00 2001 From: exside Date: Sat, 13 Sep 2014 17:45:22 +0200 Subject: [PATCH 11/11] Correct console log message on manual cache clearing --- .../elementhelper/elements/plugins/plugin.elementhelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php index 7d2fcba..5975bcb 100644 --- a/core/components/elementhelper/elements/plugins/plugin.elementhelper.php +++ b/core/components/elementhelper/elements/plugins/plugin.elementhelper.php @@ -108,7 +108,7 @@ function get_files($directory_path, $modx) // Create all the templates, snippets, chunks and plugins foreach ($element_types as $element_type) { - $log_prefix = '[' . $packagename . '] ' . $element_type['class_name'] . ': '; + $log_prefix = '[' . $classname . '] ' . $element_type['class_name'] . ': '; $file_list = get_files(MODX_BASE_PATH . $element_type['path'], $modx); $file_name = array();