/** * Update the applications bootstrap.php file. * * @param string $plugin Name of plugin. * @param bool $hasBootstrap Whether or not bootstrap should be loaded. * @param bool $hasRoutes Whether or not routes should be loaded. * @param bool $hasAutoloader Whether or not there is an autoloader configured for * the plugin. * @return bool If modify passed. */ protected function _modifyBootstrap($plugin, $hasBootstrap, $hasRoutes, $hasAutoloader) { $bootstrap = new File($this->bootstrap, false); $contents = $bootstrap->read(); if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) { $autoloadString = $hasAutoloader ? "'autoload' => true" : ''; $bootstrapString = $hasBootstrap ? "'bootstrap' => true" : ''; $routesString = $hasRoutes ? "'routes' => true" : ''; $append = "\nPlugin::load('%s', [%s]);\n"; $options = implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString])); $bootstrap->append(str_replace(', []', '', sprintf($append, $plugin, $options))); $this->out(''); $this->out(sprintf('%s modified', $this->bootstrap)); return true; } return false; }
/** * Update the app's bootstrap.php file. * * @param string $plugin Name of plugin * @param bool $hasAutoloader Whether or not there is an autoloader configured for * the plugin * @return void */ protected function _modifyBootstrap($plugin, $hasAutoloader) { $bootstrap = new File($this->bootstrap, false); $contents = $bootstrap->read(); if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) { $autoload = $hasAutoloader ? null : "'autoload' => true, "; $bootstrap->append(sprintf("\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => true]);\n", $plugin, $autoload)); $this->out(''); $this->out(sprintf('%s modified', $this->bootstrap)); } }
public function createFileFromChunks($chunkFiles, $destFile) { $destFile = new File($destFile, true); foreach ($chunkFiles as $chunkFile) { $file = new File($chunkFile); $destFile->append($file->read()); } return $destFile->exists(); }
/** * _addPluginToBootstrap * * Quick method to add a plugin to the bootstrap file. * This is useful for the tests * * @param string $name */ protected function _addPluginToBootstrap($name) { $bootstrap = new File($this->bootstrap, false); $bootstrap->append("\n\nPlugin::load('{$name}', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);\n"); }
/** * testAppend method * * @return void */ public function testAppend() { if (!($tmpFile = $this->_getTmpFile())) { return false; } if (file_exists($tmpFile)) { unlink($tmpFile); } $TmpFile = new File($tmpFile); $this->assertFalse(file_exists($tmpFile)); $fragments = ['CakePHP\'s', ' test suite', ' was here ...']; $data = null; $size = 0; foreach ($fragments as $fragment) { $r = $TmpFile->append($fragment); $this->assertTrue($r); $this->assertTrue(file_exists($tmpFile)); $data = $data . $fragment; $this->assertEquals($data, file_get_contents($tmpFile)); $newSize = $TmpFile->size(); $this->assertTrue($newSize > $size); $size = $newSize; $TmpFile->close(); } $TmpFile->append(''); $this->assertEquals($data, file_get_contents($tmpFile)); $TmpFile->close(); }
public function createFileFromChunks($chunkFiles, $destFile) { $this->log('Beginning of create files from chunks'); natsort($chunkFiles); $destFile = new File($destFile, true); foreach ($chunkFiles as $chunkFile) { $file = new File($chunkFile); $destFile->append($file->read()); $this->log('Append ', ['chunk file' => $chunkFile]); } $this->log('End of create files from chunks'); return $destFile->exists(); }
public function export() { $tableName = ''; $table = ''; //get form data if ($this->request->is('post')) { $table = $this->request->data['table']; } //process if ($this->request->is('post')) { $str = ''; if ($table == 0) { $tableName = 'tickets'; $ticketsTable = TableRegistry::get('tickets'); $query = $ticketsTable->find('all'); $str = "id" . "," . "theater_id" . "," . "section_id" . "," . "row_id" . "," . "seat_id" . "," . "status" . "," . "customer_id" . "," . "customer_name" . "," . "ticket_number" . "," . "performance_id" . "," . "season_id" . "," . "purchase_id\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= $item->theater_id . ","; $str .= $item->section_id . ","; $str .= $item->row_id . ","; $str .= $item->seat_id . ","; $str .= $item->status . ","; $str .= $item->customer_id . ","; $str .= "\"" . $item->customer_name . "\"" . ","; $str .= $item->ticket_number . ","; $str .= $item->performance_id . ","; $str .= $item->season_id . ","; $str .= $item->purchase_id; $str .= "\r\n"; } } elseif ($table == 1) { $tableName = 'staffAssignments'; $staffAssignmentsTable = TableRegistry::get('staffAssignments'); $query = $staffAssignmentsTable->find('all'); $str = "id" . "," . "user_id" . "," . "theater_id" . "," . "access_level\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= $item->user_id . ","; $str .= $item->theater_id . ","; $str .= $item->access_level; $str .= "\r\n"; } } elseif ($table == 2) { $tableName = 'users'; $ticketsTable = TableRegistry::get('users'); $query = $ticketsTable->find('all'); $str = "id" . "," . "name" . "," . "street" . "," . "city" . "," . "state" . "," . "zip" . "," . "phone_number" . "," . "email" . "," . "password" . "," . "is_super_admin" . "," . "date_created" . "," . "date_modified" . "," . "salt\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->name . "\"" . ","; $str .= "\"" . $item->street . "\"" . ","; $str .= "\"" . $item->city . "\"" . ","; $str .= "\"" . $item->state . "\"" . ","; $str .= "\"" . $item->zip . "\"" . ","; $str .= "\"" . $item->phone_number . "\"" . ","; $str .= "\"" . $item->email . "\"" . ","; $str .= "\"" . $item->password . "\"" . ","; $str .= $item->is_super_admin . ","; $str .= "\"" . $item->date_created . "\"" . ","; $str .= "\"" . $item->date_modified . "\"" . ","; $str .= "\"" . $item->salt . "\""; $str .= "\r\n"; } } elseif ($table == 3) { $tableName = 'theaters'; $theatersTable = TableRegistry::get('theaters'); $query = $theatersTable->find('all'); $str = "id" . "," . "name" . "," . "sales_tax" . "," . "description" . "," . "location" . "," . "artwork\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->name . "\"" . ","; $str .= $item->sales_tax . ","; $str .= "\"" . $item->description . "\"" . ","; $str .= "\"" . $item->location . "\"" . ","; $str .= "\"" . $item->artwork . "\""; $str .= "\r\n"; } } elseif ($table == 4) { $tableName = 'sections'; $sectionsTable = TableRegistry::get('sections'); $query = $sectionsTable->find('all'); $str = "id" . "," . "name" . "," . "code" . "," . "theater_id" . "," . "accessible_section" . "," . "front_text" . "," . "back_text\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->name . "\"" . ","; $str .= "\"" . $item->code . "\"" . ","; $str .= $item->theater . ","; $str .= $item->accessible_section . ","; $str .= "\"" . $item->front_text . "\"" . ","; $str .= "\"" . $item->back_text . "\""; $str .= "\r\n"; } } elseif ($table == 5) { $tableName = 'seats'; $seatsTable = TableRegistry::get('seats'); $query = $seatsTable->find('all'); $str = "id" . "," . "theater" . "," . "section" . "," . "row" . "," . "code" . "," . "price\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= $item->theater_id . ","; $str .= $item->section_id . ","; $str .= $item->row_id . ","; $str .= "\"" . $item->code . "\"" . ","; $str .= $item->price; $str .= "\r\n"; } } elseif ($table == 6) { $tableName = 'seasons'; $seasonsTable = TableRegistry::get('seasons'); $query = $seasonsTable->find('all'); $str = "id" . "," . "name" . "," . "start_time" . "," . "end_time" . "," . "ticket_price" . "," . "theater_id" . "\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->name . "\"" . ","; $str .= $item->start_time . ","; $str .= $item->end_time . ","; $str .= $item->ticket_price . ","; $str .= $item->theater_id . ","; $str .= "\"" . $item->about . "\""; $str .= "\r\n"; } } elseif ($table == 7) { $tableName = 'rows'; $rowsTable = TableRegistry::get('rows'); $query = $rowsTable->find('all'); $str = "id" . "," . "theater" . "," . "section" . "," . "code\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= $item->theater_id . ","; $str .= $item->section_id . ","; $str .= "\"" . $item->code . "\""; $str .= "\r\n"; } } elseif ($table == 8) { $tableName = 'plays'; $playsTable = TableRegistry::get('plays'); $query = $playsTable->find('all'); $str = "id" . "," . "name" . "," . "artwork" . "," . "description" . "," . "author\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->name . "\"" . ","; $str .= "\"" . $item->artwork . "\"" . ","; $str .= "\"" . $item->description . "\"" . ","; $str .= "\"" . $item->author . "\"" . ","; $str .= "\"" . $item->shortname . "\""; $str .= "\r\n"; } } elseif ($table == 9) { $tableName = 'performances'; $ticketsTable = TableRegistry::get('performances'); $query = $ticketsTable->find('all'); $str = "id" . "," . "start_time" . "," . "open" . "," . "canceled" . "," . "play_id" . "," . "theater_id" . "," . "season_id\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= $item->start_time . ","; $str .= $item->open . ","; $str .= $item->canceled . ","; $str .= $item->play_id . ","; $str .= $item->theater_id . ","; $str .= $item->season_id; $str .= "\r\n"; } } elseif ($table == 10) { $tableName = 'cart_items'; $ticketsTable = TableRegistry::get('cart_items'); $query = $ticketsTable->find('all'); $str = "id" . "," . "cart_id" . "," . "performance_id" . "," . "seat_id" . "," . "season_ticket\r\n"; $results = $query->toArray(); foreach ($results as $item) { $str .= $item->id . ","; $str .= "\"" . $item->cart_id . "\"" . ","; $str .= "\"" . $item->performance_id . "\"" . ","; $str .= $item->seat_id . ","; $str .= $item->season_id; $str .= "\r\n"; } } else { $this->Flash->error('Unexpected table value'); } $file = new File('tmp/', true); $file->open('w'); $file->append($str); $this->response->file($file->path, ['download' => true, 'name' => $tableName . '.csv']); } else { $this->set('file_status', 'Please submit a file.'); } }
/** * 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; }