/** * Backup database. */ public function showBackup() { $this->showMainMenu(); $tables = array(); $selectedTables = array(); foreach (Curry_Propel::getModels() as $package => $classes) { $selectedTables = array_merge($selectedTables, array_values($classes)); $tables[$package] = array(); foreach ($classes as $table) { $tables[$package][$table] = $table; } } $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'elements' => array('tables' => array('multiselect', array('label' => 'Tables', 'multiOptions' => $tables, 'value' => $selectedTables, 'size' => 15)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'value' => 'backup_%Y-%m-%d_%H-%M-%S.txt', 'description' => 'Name of the file, strftime() is used to format the string.')), 'type' => array('radio', array('label' => 'Where do you want to save?', 'multiOptions' => array('online' => 'Save online', 'local' => 'Save to local file'), 'value' => 'online'))))); $form->addElement('submit', 'Go'); if (isPost() && ($_POST['tables'] == '*' || $_POST['tables'] == array('*'))) { $_POST['tables'] = $selectedTables; } if (isPost() && $form->isValid($_POST)) { $values = $form->getValues(); if ($values['type'] == 'local') { // dump to temp, stream to client $fp = fopen("php://temp", 'r+'); Curry_Backend_DatabaseHelper::dumpDatabase($fp, $values['tables'], $this); rewind($fp); $name = Curry_String::getRewriteString(Curry_Core::$config->curry->name) . '-db.txt'; Curry_Application::returnData($fp, 'application/octet-stream', $name); } else { if ($values['type'] == 'online') { $filename = Curry_Backend_DatabaseHelper::createBackupName($values['name']); $status = Curry_Backend_DatabaseHelper::dumpDatabase($filename, $values['tables'], $this); $this->addMessage('Backup created ' . $filename, $status ? self::MSG_SUCCESS : self::MSG_ERROR); } } } $this->addMainContent($form); }