public function translations() { $models = array_diff(App::objects('model'), array('AppModel')); $translations = array(); $out = "<?php "; foreach ($models as $model) { $Model = ClassRegistry::init($model); $translations[Inflector::humanize(Inflector::underscore($Model->name))] = true; $translations[$Model->brwConfig['names']['singular']] = true; $translations[$Model->brwConfig['names']['plural']] = true; $schema = (array) $Model->schema(); foreach ($schema as $key => $value) { $translations[Inflector::humanize(str_replace('_id', '', $key))] = true; } foreach ($Model->brwConfig['custom_actions'] as $action => $config) { $translations[$config['title']] = true; if ($config['confirmMessage']) { $translations[$config['confirmMessage']] = true; } } } $translations = array_keys($translations); foreach ($translations as $translation) { $out .= "__('" . $translation . "');\n"; } $forTranslate = ROOT . DS . APP_DIR . DS . 'View' . DS . 'Elements' . DS . '4translate.php'; fwrite(fopen($forTranslate, 'w'), $out); }
public function admin_index() { if ($this->request->is('post') && isset($this->request->data)) { $models = $this->request->data['Audit']['models']; $models = array_combine(array_values($models), array_values($models)); $this->Setting->write('Audit.models', json_encode($models)); return $this->redirect(array('action' => 'index')); } $plugins = App::objects('plugin'); $models = array(); $cakePlugin = new CakePlugin(); foreach ($plugins as $plugin) { if (!$cakePlugin->loaded($plugin)) { continue; } $pluginModels = App::objects($plugin . '.Model'); foreach ($pluginModels as $pluginModel) { if (substr($pluginModel, -8) == 'AppModel') { continue; } $model = $plugin . '.' . $pluginModel; $models[$model] = $model; } } $this->request->data = array('Audit' => array('models' => json_decode(Configure::read('Audit.models'), true))); $this->set(compact('models')); }
/** * Run Migrations and add data in table * * @return If migrations have succeeded */ public function setupDatabase() { $plugins = Configure::read('Core.corePlugins'); $migrationsSucceed = true; foreach ($plugins as $plugin) { $migrationsSucceed = $this->runMigrations($plugin); if (!$migrationsSucceed) { break; } } if ($migrationsSucceed) { $path = App::pluginPath('Install') . DS . 'Config' . DS . 'Data' . DS; $dataObjects = App::objects('class', $path); foreach ($dataObjects as $data) { include $path . $data . '.php'; $classVars = get_class_vars($data); $modelAlias = substr($data, 0, -4); $table = $classVars['table']; $records = $classVars['records']; App::uses('Model', 'Model'); $modelObject =& new Model(array('name' => $modelAlias, 'table' => $table, 'ds' => 'default')); if (is_array($records) && count($records) > 0) { foreach ($records as $record) { $modelObject->create($record); $modelObject->save(); } $modelObject->getDatasource()->resetSequence($modelObject->useTable, $modelObject->primaryKey); } ClassRegistry::removeObject($modelAlias); } } return $migrationsSucceed; }
/** * Sets the plugins folder for this test * * @return void */ public function setUp() { parent::setUp(); App::build(array( 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) ), App::RESET); App::objects('plugins', null, false); }
/** * Overwrite shell initialize to dynamically load all queue related tasks. * * @return void */ public function initialize() { // Check for tasks inside plugins and application $paths = App::path('Console/Command/Task'); foreach ($paths as $path) { $Folder = new Folder($path); $res = array_merge($this->tasks, $Folder->find('Queue.*\\.php')); foreach ($res as &$r) { $r = basename($r, 'Task.php'); } $this->tasks = $res; } $plugins = App::objects('plugin'); foreach ($plugins as $plugin) { $pluginPaths = App::path('Console/Command/Task', $plugin); foreach ($pluginPaths as $pluginPath) { $Folder = new Folder($pluginPath); $res = $Folder->find('Queue.*Task\\.php'); foreach ($res as &$r) { $r = $plugin . '.' . basename($r, 'Task.php'); } $this->tasks = array_merge($this->tasks, $res); } } $conf = Configure::read('Queue'); if (!is_array($conf)) { $conf = []; } // Merge with default configuration vars. Configure::write('Queue', array_merge(['workers' => 3, 'sleepTime' => 10, 'gcprop' => 10, 'defaultWorkerTimeout' => 2 * MINUTE, 'defaultWorkerRetries' => 4, 'workerMaxRuntime' => 0, 'cleanupTimeout' => DAY, 'exitWhenNothingToDo' => false], $conf)); parent::initialize(); }
public function _getFiles($type) { $files = App::objects($type); # lib $paths = (array) App::path($type . 's'); $libFiles = App::objects($type, $paths[0] . 'lib' . DS, false); $plugins = App::objects('plugin'); if (!empty($plugins)) { foreach ($plugins as $plugin) { $pluginFiles = App::objects($type, App::pluginPath($plugin) . $type . 's' . DS, false); if (!empty($pluginFiles)) { foreach ($pluginFiles as $t) { $files[] = $t; //"$plugin.$type"; } } } } $files = array_merge($files, $libFiles); $files = array_unique($files); $appIndex = array_search('App', $files); if ($appIndex !== false) { unset($files[$appIndex]); } # no test/tmp files etc (helper.test.php or helper.OLD.php) foreach ($files as $key => $file) { if (strpos($file, '.') !== false || !preg_match('/^[\\da-zA-Z_]+$/', $file)) { unset($files[$key]); } } return $files; }
/** * Returns a list of controllers and actions belonging to plugins * * @access public * @return array */ public function get_plugins() { $pluginDirs = App::objects('plugin', null, false); $plugins = array(); foreach ($pluginDirs as $pluginDir){ $pluginClasses = App::objects('controller', APP.'Plugin'. DS .$pluginDir. DS .'Controller', false); App::import('Controller', $pluginDir.'.'.$pluginDir.'App'); $parentActions = get_class_methods($pluginDir.'AppController'); foreach($pluginClasses as $plugin) { if (strpos($plugin,'App') === false) { $plugin = str_ireplace('Controller', '', $plugin); App::import('Controller', $pluginDir.'.'.$plugin); $actions = get_class_methods($plugin.'Controller'); foreach($actions as $k => $v) { if ($v{0} == '_') { unset($actions[$k]); } } $plugins[$pluginDir][$plugin] = array_diff($actions, $parentActions); } } } return $plugins; }
/** * Execution method always used for tasks * * @return void */ public function execute() { parent::execute(); //引数のセット if (isset($this->params[self::KEY_APACHE_OWNER])) { $owner = Hash::get($this->params, self::KEY_APACHE_OWNER); $writables = array(APP . 'Config', APP . 'tmp', ROOT . DS . 'composer.json', ROOT . DS . 'bower.json'); foreach ($writables as $file) { $messages = array(); $ret = null; $cmd = sprintf('`which chown` %s -R %s 2>&1', $owner, $file); exec($cmd, $messages, $ret); } } if (array_key_exists(self::KEY_RELEASE, $this->params)) { $path = ROOT . DS . 'app' . DS . 'Plugin' . DS; $plugins = array_unique(array_merge(App::objects('plugins'), array_map('basename', glob($path . '*', GLOB_ONLYDIR)))); $folder = new Folder(); foreach ($plugins as $plugin) { $folder->delete($path . $plugin . DS . '.git'); } $folder->delete(ROOT . DS . '.git'); $folder->delete(ROOT . DS . '.chef'); } Configure::write('NetCommons.installed', true); $this->InstallUtil->saveAppConf(); }
/** * Overwrite shell initialize to dynamically load all Queue Related Tasks. * * @return void */ public function initialize() { $this->_loadModels(); $x = App::objects('Queue.Task'); //'Console/Command/Task' //$x = App::path('Task', 'Queue'); $paths = App::path('Console/Command/Task'); foreach ($paths as $path) { $Folder = new Folder($path); $this->tasks = array_merge($this->tasks, $Folder->find('Queue.*\\.php')); } $plugins = App::objects('plugin'); foreach ($plugins as $plugin) { $pluginPaths = App::path('Console/Command/Task', $plugin); foreach ($pluginPaths as $pluginPath) { $Folder = new Folder($pluginPath); $res = $Folder->find('Queue.*Task\\.php'); foreach ($res as &$r) { $r = $plugin . '.' . basename($r, 'Task.php'); } $this->tasks = array_merge($this->tasks, $res); } } //Config can be overwritten via local app config. Configure::load('Queue.queue'); $conf = (array) Configure::read('Queue'); //merge with default configuration vars. Configure::write('Queue', array_merge(['maxruntime' => DAY, 'cleanuptimeout' => MONTH], $conf)); }
public function modelExists($model) { if ($model == 'BrwUser') { return true; } return in_array($model, App::objects('model')); }
/** * set menu with app objects controllers or with $menuItems = array('Query', 'Register', 'Plan', 'Verify'); * * @return void * @access protected * @throws */ protected function _setMenu() { if (isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin') { $excludedMenuItems = array('PhkapaApp', 'Phkapa', 'Query', 'Verify', 'Review', 'Register', 'Plan'); $menuItems = App::objects('Phkapa.Controller'); foreach ($excludedMenuItems as $item) { $item .= 'Controller'; if (array_search($item, $menuItems) !== '') { unset($menuItems[array_search($item, $menuItems)]); } } foreach ($menuItems as $key => $value) { $menuItems[$key] = str_replace('Controller', '', $value); } sort($menuItems); } else { $menuItems = array('Query', 'Register', 'Review', 'Plan', 'Verify'); $user = $this->Auth->user('name'); /* foreach ($menuItems as $key => $value): if (!$this->checkAccess($value, $user)) { unset($menuItems[$key]); } endforeach; */ } $this->set(compact('menuItems')); }
/** * set menu with app objects controllers or with $menuItems = array('Query', 'Register', 'Plan', 'Verify'); * * @return void * @access protected * @throws */ protected function _setMenu() { if (isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin') { $excludedMenuItems = array('PhkapaApp', 'Phkapa', 'Query', 'Verify', 'Review', 'Register', 'Plan'); $menuItems = App::objects('Phkapa.Controller'); foreach ($excludedMenuItems as $item) { $item .= 'Controller'; if (array_search($item, $menuItems) !== '') { unset($menuItems[array_search($item, $menuItems)]); } } foreach ($menuItems as $key => $value) { $menuItems[$key] = str_replace('Controller', '', $value); } sort($menuItems); $this->set('user_at_string', __n('User', 'Users', 1) . ' ' . $this->Session->read('Auth.User.name') . ' @ ' . __('pHKapa Setup')); } else { $menuItems = array('Query', 'Register', 'Review', 'Plan', 'Verify'); $user = $this->Auth->user('name'); /* foreach ($menuItems as $key => $value): if (!$this->checkAccess($value, $user)) { unset($menuItems[$key]); } endforeach; */ $this->set('user_at_string', __n('User', 'Users', 1) . ' ' . $this->Session->read('Auth.User.name') . ' @ ' . __('pHKapa')); } $translationDomain = 'phkapa'; $this->set(compact('menuItems', 'translationDomain')); }
public function index() { if (empty($this->data)) { $modelIgnoreList = Configure::read('ReportManager.modelIgnoreList'); $models = App::objects('Model'); $models = array_combine($models, $models); if (isset($modelIgnoreList) && is_array($modelIgnoreList)) { foreach ($modelIgnoreList as $model) { if (isset($models[$model])) { } unset($models[$model]); } } $this->set('files', $this->listReports()); $this->set('models', $models); } else { $modelClass = null; $oneToManyOption = null; $fileName = $this->data['ReportManager']['saved_report_option']; if ($fileName != '') { $params = explode('.', $fileName); if (count($params) >= 3) { $modelClass = $params[0]; if (count($params) > 3) { $oneToManyOption = $params[1]; } } } else { $modelClass = $this->data['ReportManager']['model']; $oneToManyOption = $this->data['ReportManager']['one_to_many_option']; } $this->redirect(array('action' => 'wizard', $modelClass, $oneToManyOption, urlencode($fileName))); } }
public function import() { if (isset($this->params['name'])) { $dataObjects = array(Inflector::camelize(Inflector::singularize($this->params['name'])) . 'Data'); } else { $dataObjects = App::objects('class', $this->directory); } $passFields = null; if (array_key_exists('pass', $this->params)) { $passFields = array('created', 'updated', 'modified'); } foreach ($dataObjects as $data) { App::import('class', $data, false, $this->directory); extract(get_class_vars($data)); if (empty($records) || !is_array($records)) { continue; } $Model = ClassRegistry::init($name); $Model->useDbConfig = $this->connection; if ($passFields) { foreach ($records as &$record) { foreach ($passFields as $field) { unset($record[$field]); } } } $Model->query("TRUNCATE `{$Model->table}`"); $success = 'Faild'; if ($Model->saveAll($records, array('validate' => false))) { $success = 'Success'; } $this->out("Data imported: {$Model->name} [{$success}]"); } }
/** * @test installing plugins */ public function testInstaller() { $this->__cleanSystem(); $this->assertTrue(App::import('lib', 'Installer.Installer'), 'Could not import the insatller lib'); $this->assertTrue(App::import('Lib', 'Installer.ReleaseVersion'), 'Could not import Versions lib'); $Installer = new InstallerLib(); $Version = new ReleaseVersion(array('connection' => 'test_suite')); $connectionDetails = $Installer->cleanConnectionDetails(array('connection' => $this->db->config)); $this->assertTrue($Installer->installPlugin($Version, $connectionDetails)); $expected = array('0' => 'acos', '1' => 'aros', '2' => 'aros_acos', '3' => 'schema_migrations', '4' => 'sessions'); $this->assertEqual($expected, $this->db->listSources()); $this->assertTrue($Installer->installPlugin($Version, $connectionDetails, 'Installer')); $expected = array('0' => 'acos', '1' => 'aros', '2' => 'aros_acos', '3' => 'core_plugins', '4' => 'schema_migrations', '5' => 'sessions'); $this->assertEqual($expected, $this->db->listSources()); $pluginsToInstall = App::objects('plugin'); natsort($pluginsToInstall); foreach ($pluginsToInstall as $k => $pluginToInstall) { if (in_array($pluginToInstall, array('Migrations'))) { continue; } $this->assertTrue($Installer->installPlugin($Version, $connectionDetails, $pluginToInstall), sprintf('%s could not be installed', $pluginToInstall)); } foreach ($pluginsToInstall as $pluginToInstall) { $this->__checkVersionCount($pluginToInstall); } }
function initialize(&$controller) { $this->controller = $controller; if (in_array('Captcha', App::objects('plugin'))) { $this->controller->helpers[] = "Captcha.Captcha"; } }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Cache.disable', true); App::build(); App::objects('plugin', null, true); }
public function index() { if (empty($this->data)) { $modelIgnoreList = Configure::read('ReportManager.modelIgnoreList'); $models = App::objects('model'); $models = array_combine($models, $models); if (isset($modelIgnoreList) && is_array($modelIgnoreList)) { foreach ($modelIgnoreList as $model) { if (isset($models[$model])) { } unset($models[$model]); } } $this->set('files', $this->listReports()); $this->set('models', $models); } else { if (isset($this->data['new'])) { $reportButton = 'new'; $modelClass = $this->data['model']; $oneToManyOption = $this->data['one_to_many_option']; $this->redirect(array('action' => 'wizard', $reportButton, $modelClass, $oneToManyOption)); } if (isset($this->data['load'])) { $reportButton = 'load'; $fileName = $this->data['saved_report_option']; $this->redirect(array('action' => 'wizard', $reportButton, urlencode($fileName))); } $this->redirect(array('action' => 'index')); } }
/** * Paints the menu on the left side of the test suite interface. * Contains all of the various plugin, core, and app buttons. * * @return void */ public function paintTestMenu() { $cases = $this->baseUrl() . '?show=cases'; $plugins = App::objects('plugin', null, false); sort($plugins); include CAKE . 'TestSuite' . DS . 'templates' . DS . 'menu.php'; }
/** * Find the paths to all the installed shell themes extensions in the app. * * @return array Array of bake themes that are installed. */ protected function _findSubthemes() { $paths = App::path('shells'); $plugins = App::objects('plugin'); foreach ($plugins as $plugin) { $paths[$plugin] = $this->_pluginPath($plugin) . 'Console' . DS; } foreach ($paths as $i => $path) { $paths[$i] = rtrim($path, DS) . DS; } $subthemes = array(); foreach ($paths as $plugin => $path) { $Folder = new Folder($path . 'SubTemplates', false); $contents = $Folder->read(); $subDirs = $contents[0]; foreach ($subDirs as $dir) { if (empty($dir) || preg_match('@^skel$|_skel|\\..+$@', $dir)) { continue; } $Folder = new Folder($path . 'SubTemplates' . DS . $dir); $contents = $Folder->read(); $subDirs = $contents[0]; $templateDir = $path . 'SubTemplates' . DS . $dir . DS; $subthemes[$plugin . '.' . $dir] = $templateDir; } } return $subthemes; }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Cache.disable', TRUE); App::build(); App::objects('plugin', NULL, TRUE); }
/** * Paints the menu on the left side of the test suite interface. * Contains all of the various plugin, core, and app buttons. * * @return void */ function paintTestMenu() { $groups = $this->baseUrl() . '?show=groups'; $cases = $this->baseUrl() . '?show=cases'; $plugins = App::objects('plugin'); include CAKE_TESTS_LIB . 'templates' . DS . 'menu.php'; }
/** * Override startup of the Shell * * @return void */ public function startup() { App::uses('Dispatcher', 'Routing'); $this->Dispatcher = new Dispatcher(); $this->models = App::objects('Model'); foreach ($this->models as $model) { $class = $model; $this->models[$model] = $class; App::uses($class, 'Model'); $this->{$class} = new $class(); } $this->out(__d('cake_console', 'Model classes:')); $this->hr(); foreach ($this->models as $model) { $this->out(" - {$model}"); } if (!$this->_loadRoutes()) { $message = __d( 'cake_console', 'There was an error loading the routes config. Please check that the file exists and contains no errors.' ); $this->err($message); } }
/** * setUp method * * @return void */ public function setUp() { $this->_cacheDisable = Configure::read('Cache.disable'); $this->_debug = Configure::read('debug'); Configure::write('Cache.disable', true); App::build(); App::objects('plugin', null, true); }
/** * Renders the menu on the top of the test suite interface. * * @return void */ public function paintTestMenu() { /** @noinspection PhpUnusedLocalVariableInspection */ $cases = $this->baseUrl() . '?show=cases'; $plugins = App::objects('plugin', null, false); sort($plugins); include APP . 'TestSuite' . DS . 'templates' . DS . 'menu.php'; }
function constructClasses() { if (in_array('Upgrader', App::objects('plugin')) && !empty($this->params['admin'])) { App::import('Lib', 'Upgrader.Upgrader'); Upgrader::requireUpgraded('Shop', $this); } return parent::constructClasses(); }
/** * @test getting all plugins within the system */ public function testGetAllPlugins() { $plugins = App::objects('plugin'); natsort($plugins); $this->assertEqual($plugins, $this->Plugin->getAllPlugins()); $this->assertEqual($plugins, $this->Plugin->getAllPlugins('list')); $this->assertEqual($plugins, $this->Plugin->getAllPlugins('whatever')); $this->assertEqual(count(App::objects('plugin')), $this->Plugin->getAllPlugins('count')); }
/** * @brief get a list of all the plugins that are in the system * * This will not check plugins that are installed, but anything within * any of the defined plugin directories. * * @access public * * @param string $type list / count * * @return array all plugins in alphabetical order */ public function getAllPlugins($type = 'list') { $plugins = App::objects('plugin'); natsort($plugins); if ($type == 'count') { return count($plugins); } return $plugins; }
/** * Returns an array of known helpers. We will cache the known helpers * so that we don't have to keep bothering App::object() * * @param boolean $cache * @return array * @access protected */ protected function _getHelpers($cache = true) { // Check if we don't have the array of if we're told not to cache if (empty($this->_helpers) or !$cache) { $this->_helpers = App::objects('helper'); } // Return the array of helpers return $this->_helpers; }
/** * Get a list of controllers in the app and plugins. * * Returns an array of path => import notation. * * @param string $plugin Name of plugin to get controllers for * @return array * */ public function getControllerList($plugin = null) { if (!$plugin) { $controllers = App::objects('Controller', null, false); } else { $controllers = App::objects($plugin . '.Controller', null, false); } return $controllers; }