function restoreDBFromBackup() { makeRed("Restore Database? WARNING: This will drop all tables and restore data to last backup!"); echo "(Y/N): "; $data = FOPEN("php://stdin", "rb"); $input = ''; while (1 == 1) { $chunk = FREAD($data, 1); if ($chunk == "\n" || $chunk == "\r") { break; } $input .= $chunk; } FCLOSE($data); if (strtolower(@$input) == 'y') { echo "Getting Credentials from application.ini...\n"; $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $bootstrap = $application->getBootstrap(); $options = $bootstrap->getOptions(); $db = $options['resources']['db']['params']; echo "Database Restoring. Please be patient, this could take a while..."; sleep(1); echo "."; sleep(1); echo "."; sleep(1); echo "."; echo "\n"; exec("mysql -u " . $db['username'] . " -p" . $db['password'] . " " . $db['dbname'] . " < " . APPLICATION_PATH . "/../data/dbbackup.sql", $output); makeGreen("DONE!"); echo "\n\n"; } else { echo "Operation Cancelled.\n"; } }
function packageApplication($path = false) { if (!$path) { $path = APPLICATION_PATH . "/../data/application.zip"; } echo "Preparing to Archive Application. Please Be Patient...\n"; if (file_exists("{$path}")) { makeRed("Removing old archive...\n"); unlink("{$path}"); } exec("zip -9 -r {$path} ../*", $output); foreach ($output as $o) { echo "{$o}\n"; } makeGreen("DONE! Archive saved to " . str_replace("application/../", '', $path)); echo "\n\n"; }
function buildController($name = false) { if (!$name) { makeRed('Please provide a name for your controller.'); die("\n"); } //Convert underscores $controllerName = str_replace("_", "", $name); //CamelCase $controllerName = ucwords($controllerName); //Remove Spaces $controllerName = str_replace(" ", "", $controllerName); if (file_exists(APPLICATION_PATH . "/controllers/" . $controllerName . "Contoller.php")) { die("This controller already exists!!\n"); } $controllerText = '<?php class ' . $controllerName . 'Controller extends Swift_Controller_Action { public function init(){ } /** * Page */ public function indexAction(){ } } '; echo "\n\n Building Class {$controllerName}...\n\n"; file_put_contents(APPLICATION_PATH . "/controllers/" . $controllerName . "Controller.php", $controllerText); echo "Done!\n"; }
function buildModel($dbTableName = false) { if (!$dbTableName) { makeRed('Please provide a database table name for your model.'); die("\n"); } //Convert underscores $modelName = str_replace("_", " ", $dbTableName); //CamelCase $modelName = ucwords($modelName); //Remove Spaces $modelName = str_replace(" ", "", $modelName); if (file_exists(APPLICATION_PATH . "/models/" . $modelName . ".php")) { die("This model already exists!!\n"); } $modelText = '<?php class ' . $modelName . ' extends Zend_DB_Table { protected $_name = "' . $dbTableName . '"; /** * Get record by ID * @param type $id * @return type object */ public function getById($id){ $select = $this->select() ->from($this->_name) ->where(\'id=?\',$id); $result = $this->fetchRow($select); return $result; } /** * Get All Records * @return type object */ public function getAll(){ $select = $this->select() ->from($this->_name); $result = $this->fetchAll($select); return $result; } /** * Update Record in Database * @param int $id * @param array $data */ function updateRecord($id,$data){ $where = "id = " . $id; $this->update($data,$where); return true; } } '; echo "\n\n Building Class {$modelName} for {$dbTableName}...\n\n"; file_put_contents(APPLICATION_PATH . "/models/" . $modelName . ".php", $modelText); echo "Done!\n"; }