/** * Look for plugin/themes awaiting for installation and sets a flash message * with instructions about how to proceed. * * @param string $type Possible values `plugin` (default) or `theme`, defaults * to "plugin" * @return void */ protected function _awaitingPlugins($type = 'plugin') { $type = !in_array($type, ['plugin', 'theme']) ? 'plugin' : $type; $ignoreThemes = $type === 'plugin'; $plugins = Plugin::scan($ignoreThemes); foreach ($plugins as $name => $path) { if (Plugin::exists($name) || $type == 'theme' && !str_ends_with($name, 'Theme')) { unset($plugins[$name]); } } if (!empty($plugins)) { $this->Flash->set(__d('system', '{0} are awaiting for installation', $type == 'plugin' ? __d('system', 'Some plugins') : __d('system', 'Some themes')), ['element' => 'System.stashed_plugins', 'params' => compact('plugins')]); } }
/** * Stores some bootstrap-handy information into a persistent file. * * Information is stored in `TMP/snapshot.php` file, it contains * useful information such as enabled languages, content types slugs, installed * plugins, etc. * * You can read this information using `Configure::read()` as follow: * * ```php * Configure::read('QuickApps.<option>'); * ``` * * Or using the `quickapps()` global function: * * ```php * quickapps('<option>'); * ``` * * @return void */ function snapshot() { if (Cache::config('default')) { Cache::clear(false, 'default'); } if (Cache::config('_cake_core_')) { Cache::clear(false, '_cake_core_'); } if (Cache::config('_cake_model_')) { Cache::clear(false, '_cake_model_'); } $versionPath = QUICKAPPS_CORE . 'VERSION.txt'; $snapshot = ['version' => null, 'content_types' => [], 'plugins' => [], 'options' => [], 'languages' => [], 'aspects' => []]; if (is_readable($versionPath)) { $versionFile = file($versionPath); $snapshot['version'] = trim(array_pop($versionFile)); } else { die(sprintf('Missing file: %s', $versionPath)); } if (ConnectionManager::config('default')) { if (!TableRegistry::exists('SnapshotPlugins')) { $PluginTable = TableRegistry::get('SnapshotPlugins', ['table' => 'plugins']); } else { $PluginTable = TableRegistry::get('SnapshotPlugins'); } if (!TableRegistry::exists('SnapshotContentTypes')) { $ContentTypesTable = TableRegistry::get('SnapshotContentTypes', ['table' => 'content_types']); } else { $ContentTypesTable = TableRegistry::get('SnapshotContentTypes'); } if (!TableRegistry::exists('SnapshotLanguages')) { $LanguagesTable = TableRegistry::get('SnapshotLanguages', ['table' => 'languages']); } else { $LanguagesTable = TableRegistry::get('SnapshotLanguages'); } if (!TableRegistry::exists('SnapshotOptions')) { $OptionsTable = TableRegistry::get('SnapshotOptions', ['table' => 'options']); } else { $OptionsTable = TableRegistry::get('SnapshotOptions'); } $PluginTable->schema(['value' => 'serialized']); $OptionsTable->schema(['value' => 'serialized']); $plugins = $PluginTable->find()->select(['name', 'package', 'status'])->order(['ordering' => 'ASC', 'name' => 'ASC'])->all(); $contentTypes = $ContentTypesTable->find()->select(['slug'])->all(); $languages = $LanguagesTable->find()->where(['status' => 1])->order(['ordering' => 'ASC'])->all(); $options = $OptionsTable->find()->select(['name', 'value'])->where(['autoload' => 1])->all(); foreach ($contentTypes as $contentType) { $snapshot['content_types'][] = $contentType->slug; } foreach ($options as $option) { $snapshot['options'][$option->name] = $option->value; } foreach ($languages as $language) { list($languageCode, $countryCode) = localeSplit($language->code); $snapshot['languages'][$language->code] = ['name' => $language->name, 'locale' => $language->code, 'code' => $languageCode, 'country' => $countryCode, 'direction' => $language->direction, 'icon' => $language->icon]; } } else { $plugins = []; foreach (Plugin::scan() as $plugin => $path) { $plugins[] = new Entity(['name' => $plugin, 'status' => true, 'package' => 'quickapps-plugins']); } } $folder = new Folder(QUICKAPPS_CORE . 'src/Aspect/'); foreach ($folder->read(false, false, true)[1] as $classFile) { $className = basename(preg_replace('/\\.php$/', '', $classFile)); if (!in_array($className, ['AppAspect', 'Aspect'])) { $snapshot['aspects'][] = "CMS\\Aspect\\{$className}"; } } foreach ($plugins as $plugin) { $pluginPath = false; if (isset(Plugin::scan()[$plugin->name])) { $pluginPath = Plugin::scan()[$plugin->name]; } if ($pluginPath === false) { Debugger::log(sprintf('Plugin "%s" was found in DB but QuickAppsCMS was unable to locate its root directory.', $plugin->name)); continue; } if (!Plugin::validateJson("{$pluginPath}/composer.json")) { Debugger::log(sprintf('Plugin "%s" has a corrupt "composer.json" file (%s).', $plugin->name, "{$pluginPath}/composer.json")); continue; } $aspectsPath = "{$pluginPath}/src/Aspect/"; $eventsPath = "{$pluginPath}/src/Event/"; $fieldsPath = "{$pluginPath}/src/Field/"; $helpFiles = glob($pluginPath . '/src/Template/Element/Help/help*.ctp'); $isTheme = str_ends_with($plugin->name, 'Theme'); $status = (bool) $plugin->status; $humanName = ''; $aspects = []; $eventListeners = []; $fields = []; $subspaces = [$aspectsPath => 'Aspect', $eventsPath => 'Event', $fieldsPath => 'Field']; $varnames = [$aspectsPath => 'aspects', $eventsPath => 'eventListeners', $fieldsPath => 'fields']; foreach ([$aspectsPath, $eventsPath, $fieldsPath] as $path) { if (is_dir($path)) { $Folder = new Folder($path); foreach ($Folder->read(false, false, true)[1] as $classFile) { $className = basename(preg_replace('/\\.php$/', '', $classFile)); $subspace = $subspaces[$path]; $varname = $varnames[$path]; $namespace = "{$plugin->name}\\{$subspace}\\"; ${$varname}[] = $namespace . $className; } } } if (is_readable("{$pluginPath}composer.json")) { $json = (array) json_decode(file_get_contents("{$pluginPath}composer.json"), true); if (!empty($json['extra']['human-name'])) { $humanName = $json['extra']['human-name']; } } if (empty($humanName)) { $humanName = (string) Inflector::humanize((string) Inflector::underscore($plugin->name)); if ($isTheme) { $humanName = trim(str_replace_last('Theme', '', $humanName)); } } $snapshot['plugins'][$plugin->name] = ['name' => $plugin->name, 'humanName' => $humanName, 'package' => $plugin->package, 'isTheme' => $isTheme, 'hasHelp' => !empty($helpFiles), 'hasSettings' => is_readable($pluginPath . '/src/Template/Element/settings.ctp'), 'aspects' => $aspects, 'eventListeners' => $eventListeners, 'fields' => $fields, 'status' => $status, 'path' => $pluginPath]; if ($status) { $snapshot['aspects'] = array_merge($snapshot['aspects'], $aspects); } } Configure::write('QuickApps', $snapshot); if (!Configure::dump('snapshot', 'QuickApps', ['QuickApps'])) { die('QuickAppsCMS was unable to create a snapshot file, check that PHP have permission to write to the "/tmp" directory.'); } }