/** * Get list modules, actions * * @return afResponse * @author Sergey Startsev */ protected function processGetList() { $root_dir = afStudioUtil::getRootDir(); $data = array(); $pluginFolders = afStudioPluginCommandHelper::getSubFolders("{$root_dir}/plugins", 'plugin'); $deprecated = afStudioPluginCommandHelper::getDeprecatedList(); foreach ($pluginFolders as $pluginFolder) { $plugin = $pluginFolder["text"]; if (in_array($plugin, $deprecated)) { continue; } $moduleFolders = afStudioPluginCommandHelper::getSubFolders("{$root_dir}/plugins/{$plugin}/modules/"); $mod_datas = array(); foreach ($moduleFolders as $moduleFolder) { $modulename = $moduleFolder["text"]; $configfiles = afStudioPluginCommandHelper::getFiles($plugin, $modulename, ".xml"); $moduleFolder["children"] = $configfiles; if (count($configfiles) == 0) { $moduleFolder["leaf"] = true; $moduleFolder["iconCls"] = "icon-folder"; } array_push($mod_datas, $moduleFolder); } $pluginFolder["children"] = $mod_datas; if (count($mod_datas) == 0) { $pluginFolder["leaf"] = true; $pluginFolder["iconCls"] = "icon-folder"; } array_push($data, $pluginFolder); } $meta = isset($data[0]) ? array_keys($data[0]) : array(); $total = count($data); return afResponseHelper::create()->success(true)->data($meta, $data, $total); }
/** * Getting grouped module list * * @param string $type * @return array * @author Sergey Startsev */ public static function getGroupedList($type) { $root = afStudioUtil::getRootDir(); $deprecated = $type == self::TYPE_PLUGIN ? afStudioPluginCommandHelper::getDeprecatedList() : array(); $data = array(); foreach (afStudioUtil::getDirectories("{$root}/{$type}s/", true) as $place) { if (in_array($place, $deprecated)) { continue; } foreach (afStudioUtil::getDirectories("{$root}/{$type}s/{$place}/modules/", true) as $module) { $data[] = array('value' => $module, 'text' => $module, 'group' => $place, 'type' => $type); } } return $data; }
/** * Adding new module to plugin functionality * * @param string $plugin - plugin name that will contain new module * @param string $name - module name * @return afResponse * @author Sergey Startsev */ private function addToPlugin($plugin, $module) { afStudioModuleCommandHelper::load('plugin'); $response = afResponseHelper::create(); if (!afStudioPluginCommandHelper::isExists(afStudioPluginCommandHelper::PLUGIN_GENERATE_MODULES)) { return $response->success(false)->message("For creating module in plugins should be installed '" . afStudioPluginCommandHelper::PLUGIN_GENERATE_MODULES . "' plugin"); } $afConsole = afStudioConsole::getInstance(); if (!$plugin || !$module) { return $response->success(false)->message("Can't create new module <b>{$module}</b> inside <b>{$plugin}</b> plugin!"); } if (!afStudioPluginCommandHelper::isExists($plugin)) { return $response->success(false)->message("Plugin '{$plugin}' doesn't exists"); } $console = $afConsole->execute("sf generate:plugin-module {$plugin} {$module}"); $isCreated = $afConsole->wasLastCommandSuccessfull(); if ($isCreated) { afsFileSystem::create()->chmod(sfConfig::get('sf_plugins_dir') . "/{$plugin}/modules/{$module}", 0664, 00, true); $console .= $afConsole->execute('sf cc'); $message = "Created module <b>{$module}</b> inside <b>{$plugin}</b> plugin!"; } else { $message = "Could not create module <b>{$module}</b> inside <b>{$plugin}</b> plugin!"; } return $response->success($isCreated)->message($message)->console($console); }
/** * Load schemas * * @return void * @author Sergey Startsev */ private function loadSchemas() { $this->dbSchema = new sfPropelDatabaseSchema(); $this->configuration = new ProjectConfiguration(null, new sfEventDispatcher()); $dirs = array_merge(array(sfConfig::get('sf_config_dir')), $this->configuration->getPluginSubPaths('/config')); $deprecated_plugins = afStudioPluginCommandHelper::getDeprecatedList(); foreach ($dirs as $k => $dir) { if (in_array(pathinfo(dirname($dir), PATHINFO_FILENAME), $deprecated_plugins)) { unset($dirs[$k]); } } $dirs = array_values($dirs); $schemas = sfFinder::type('file')->name('*schema.yml')->prune('doctrine')->maxdepth(1)->in($dirs); foreach ($schemas as $schema_path) { $schema = DIRECTORY_SEPARATOR != '/' ? str_replace('/', DIRECTORY_SEPARATOR, $schema_path) : $schema_path; $this->originalSchemaArray[$schema] = sfYaml::load($schema); if (!is_array($this->originalSchemaArray[$schema])) { continue; } if (!isset($this->originalSchemaArray[$schema]['classes'])) { // Old schema syntax: we convert it $this->propelSchemaArray[$schema] = $this->dbSchema->convertOldToNewYaml($this->originalSchemaArray[$schema]); } $customSchemaFilename = str_replace(array(str_replace(DIRECTORY_SEPARATOR, '/', sfConfig::get('sf_root_dir')) . '/', 'plugins/', 'config/', '/', 'schema.yml'), array('', '', '', '_', 'schema.custom.yml'), $schema); $customSchemas = sfFinder::type('file')->name($customSchemaFilename)->in($dirs); foreach ($customSchemas as $customSchema) { $this->originalSchemaArray[$customSchema] = sfYaml::load($customSchema); if (!isset($this->originalSchemaArray[$customSchema]['classes'])) { // Old schema syntax: we convert it $this->propelSchemaArray[$customSchema] = $this->dbSchema->convertOldToNewYaml($this->originalSchemaArray[$customSchema]); } } } }
/** * Getting widget list action * * @return afResponse * @author Sergey Startsev */ protected function processGetWidgetList() { $root_dir = sfConfig::get('sf_root_dir'); $deprecated = afStudioPluginCommandHelper::getDeprecatedList(); $data = array(); foreach (array('app', 'plugin') as $type) { foreach (afStudioUtil::getDirectories("{$root_dir}/{$type}s/", true) as $parent) { if (in_array($parent, $deprecated)) { continue; } $widgets = $this->getWidgets($parent, $type); if (!empty($widgets)) { $data[] = $widgets; } } } return afResponseHelper::create()->success(true)->data(array(), $data, 0); }