/** * Turn cakebox-console debug mode on/off by replacing value in app.php. * * @param string $mode String containing either 'on' or 'off' * @return boolean True on success */ public function debug($mode) { $appConfig = '/cakebox/console/config/app.php'; // enable debug mode if ($mode === 'on') { $this->out("Enabling Cakebox debug mode"); if (!CakeboxUtility::updateConfigFile($appConfig, ["'debug' => false" => "'debug' => true"])) { $this->exitBashError("Error enabling Cakebox debug mode."); } $this->exitBashSuccess("Command completed successfully"); return true; } // disable debug mode $this->out("Disabling Cakebox debug mode"); if (!CakeboxUtility::updateConfigFile($appConfig, ["'debug' => true" => "'debug' => false"])) { $this->exitBashError("Error disabling Cakebox debug mode."); } $this->exitBashSuccess("Command completed successfully"); return true; }
/** * Box-fix: composer update globally installed cakephp-codesniffer * by updating version in composer.json (if needed) and then running * composer update. * * @return boolean True on success */ protected function _updateCakephpCodeSniffer() { $this->logInfo('Updating CakePHP Code Sniffer'); // update package version in composer.json to 2.* $path = '/opt/composer-libraries/cakephp_codesniffer'; $requiredVersion = '2.*'; $result = CakeboxUtility::updateConfigFile("{$path}/composer.json", ['2.*@dev' => '2.*'], true); // composer update CakePHP Coding Standard $this->logInfo('* Composer updating'); $command = "composer update --no-dev --working-dir {$path}"; if (!$this->Execute->shell($command, 'root')) { return false; } return true; }
/** * Convenience function to update all required CakePHP2 configuration files. * * @param string $appdir Full path to the application directory (APP). * @param string $url FQDN used to expose the application. * @return boolean True if the file was updated successfully */ public function updateCake2Configuration($appdir, $url) { # Update salt/cipher in core.php $this->_log("Updating core.php"); $coreFile = $appdir . DS . "app" . DS . "Config" . DS . "core.php"; $res = CakeboxUtility::updateConfigFile($coreFile, [$this->Info->frameworkMeta['cakephp2']['salt'] => CakeboxUtility::getSaltCipher($coreFile), $this->Info->frameworkMeta['cakephp2']['cipher'] => CakeboxUtility::getSaltCipher($coreFile)]); if (!$res) { $this->_error("Error updating core file"); return false; } // create database.php $dbFileSource = $appdir . DS . "app" . DS . "Config" . DS . "database.php.default"; $dbFileTarget = $appdir . DS . "app" . DS . "Config" . DS . "database.php"; if (!file_exists($dbFileTarget)) { copy($dbFileSource, $dbFileTarget); $this->_log("Created database file `{$dbFileTarget}`"); } # update database.php $this->_log("Updating database.php"); $database = CakeboxUtility::normalizeDatabaseName($url); $result = CakeboxUtility::updateConfigFile($dbFileTarget, ['test_database_name' => 'test_' . $database, 'database_name' => $database, 'user' => 'cakebox', "'password' => 'password'" => "'password' => 'secret'"]); if (!$result) { $this->_error("Error updating database file"); return false; } # Enable debugkit in bootstrap.php $this->_log("Enabling DebugKit"); $bootstrapFile = $appdir . DS . "app" . DS . "Config" . DS . "bootstrap.php"; $fh = new File($bootstrapFile); $fh->append('CakePlugin::loadAll();'); return true; }