Esempio n. 1
0
 /**
  * Create an archive of the project.
  */
 public function showBundle()
 {
     $this->addMainMenu();
     $this->addMessage('You can install this bundle using <a href="' . url('', array('module', 'view' => 'InstallScript')) . '">this installation script</a>.', self::MSG_NOTICE, false);
     $form = new \Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('project' => array('checkbox', array('label' => 'Project', 'value' => true)), 'www' => array('checkbox', array('label' => 'WWW folder', 'value' => true)), 'vendor' => array('checkbox', array('label' => 'Vendor', 'value' => true)), 'database' => array('checkbox', array('label' => 'Database', 'value' => true)), 'compression' => array('select', array('label' => 'Compression', 'multiOptions' => array(Archive::COMPRESSION_NONE => 'None', Archive::COMPRESSION_GZ => 'Gzip'))), 'save' => array('submit', array('label' => 'Create bundle')))));
     if (isPost() && $form->isValid($_POST)) {
         // create archive
         @set_time_limit(0);
         $compression = $form->compression->getValue();
         $tar = new Archive('', $compression);
         // set up file list
         $options = array(array('pattern' => '*.svn*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '*.git*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '.DS_Store', 'skip' => true), array('pattern' => 'Thumbs.db', 'skip' => true), array('pattern' => '._*', 'skip' => true));
         if ($form->project->isChecked()) {
             $tar->add($this->app['projectPath'], 'cms/', array_merge($options, array(array('path' => 'data/', 'pattern' => 'data/*/*', 'pattern_subject' => 'path', 'skip' => true))));
         }
         if ($form->www->isChecked()) {
             $tar->add($this->app['wwwPath'], 'www/', $options);
         }
         if ($form->vendor->isChecked()) {
             $tar->add($this->app['projectPath'] . '/../vendor', 'vendor/', $options);
         }
         if ($form->database->isChecked()) {
             $fiveMBs = 5 * 1024 * 1024;
             $fp = fopen("php://temp/maxmemory:{$fiveMBs}", 'r+');
             if (!\Curry_Backend_DatabaseHelper::dumpDatabase($fp)) {
                 throw new \Exception('Aborting: There was an error when dumping the database.');
             }
             fseek($fp, 0);
             $tar->addString('db.txt', stream_get_contents($fp));
             fclose($fp);
         }
         $filename = str_replace(" ", "_", $this->app['name']) . "-bundle-" . date("Ymd") . ".tar" . ($compression ? ".{$compression}" : '');
         header("Content-type: " . Archive::getCompressionMimeType($compression));
         header("Content-disposition: attachment; filename=" . StringHelper::escapeQuotedString($filename));
         // do not use output buffering
         while (ob_end_clean()) {
         }
         $tar->stream();
         exit;
     }
     $this->addMainContent($form);
     return parent::render();
 }
Esempio n. 2
0
 public function saveConfiguration($values)
 {
     // Restore database from backup?
     if ($values['template'] == 'backup') {
         if (!Curry_Backend_DatabaseHelper::restoreFromFile('db.txt')) {
             $this->addMessage('Unable to restore database content from db.txt', self::MSG_WARNING);
         }
     }
     // Create admin user
     if ($values['admin']['username']) {
         $access = array('*', 'Curry_Backend_Content/*');
         $adminRole = self::createRole('Super', $access);
         $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole);
         if ($adminUser->isNew()) {
             self::createFilebrowserAccess($adminRole, 'Root', '');
         }
         $adminUser->save();
     }
     // Create light user
     if ($values['user']['username']) {
         $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*');
         $userRole = self::createRole('User', $access);
         $user = self::createUser($values['user']['username'], $values['user']['password'], $userRole);
         if ($user->isNew()) {
             $user->save();
             self::createFilebrowserAccess($user, 'Home', 'user-content/' . $user->getUserId() . '/');
             self::createFilebrowserAccess($userRole, 'Shared', 'content/');
         }
         $user->save();
     }
     if ($values['template'] != 'backup') {
         // Create default meta-data items
         $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage');
         foreach ($metadatas as $name => $type) {
             $metadata = new Metadata();
             $metadata->setName($name);
             $metadata->setDisplayName($name);
             $metadata->setType($type);
             $metadata->save();
         }
         $page = new Page();
         $page->setName("Home");
         $page->setURL("/");
         $page->setVisible(true);
         $page->setEnabled(true);
         $page->makeRoot();
         $page->save();
         $page->createDefaultRevisions();
         $page->save();
         $pageRev = $page->getWorkingPageRevision();
         $pageRev->setTemplate('Root.html');
         $pageRev->save();
         $pa = new PageAccess();
         $pa->setPage($page);
         $pa->setPermSubpages(true);
         $pa->setPermVisible(true);
         $pa->setPermCreatePage(true);
         $pa->setPermCreateModule(true);
         $pa->setPermPublish(true);
         $pa->setPermProperties(true);
         $pa->setPermContent(true);
         $pa->setPermMeta(true);
         $pa->setPermModules(true);
         $pa->setPermRevisions(true);
         $pa->setPermPermissions(true);
         $pa->save();
     }
     // Create template root
     $templateRoot = Curry_Core::$config->curry->template->root;
     if (!file_exists($templateRoot)) {
         @mkdir($templateRoot, 0777, true);
     }
     switch ($values['template']) {
         case 'empty':
         case 'curry':
             $source = Curry_Util::path(Curry_Core::$config->curry->wwwPath, 'shared', 'backend', 'common', 'templates', 'project-empty.html');
             $templateFile = Curry_Util::path($templateRoot, 'Root.html');
             if (!file_exists($templateFile)) {
                 @copy($source, $templateFile);
             }
             break;
         case 'twitter-bootstrap':
         case 'html5boilerplate':
     }
     if (file_exists(Curry_Core::$config->curry->configPath)) {
         $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true);
         $config->curry->name = $values['name'];
         $config->curry->adminEmail = $values['email'];
         if ($values['base_url']) {
             $config->curry->baseUrl = $values['base_url'];
         } else {
             unset($config->curry->baseUrl);
         }
         $config->curry->developmentMode = (bool) $values['development_mode'];
         $config->curry->secret = sha1(uniqid(mt_rand(), true) . microtime());
         $writer = new Zend_Config_Writer_Array();
         $writer->write(Curry_Core::$config->curry->configPath, $config);
     }
     return true;
 }
Esempio n. 3
0
 protected function saveConnection($params, $propelConfig)
 {
     $success = true;
     // Get adapter configuration
     $adapter = null;
     switch ($params['adapter']) {
         case 'mysql':
             $adapter = 'mysql';
             $dsn = "mysql:host={$params['host']};dbname={$params['database']}";
             $username = strlen($params['user']) ? $params['user'] : null;
             $password = strlen($params['password']) ? $params['password'] : null;
             break;
         default:
             $this->addMessage("Adapter configuration not supported, please configure database settings manually.", self::MSG_ERROR);
             return false;
     }
     // Update runtime configuration
     $config = new \SimpleXMLElement(file_get_contents($propelConfig));
     $defaultDataSource = (string) $config->propel->datasources['default'];
     foreach ($config->propel->datasources->datasource as $datasource) {
         if ((string) $datasource['id'] == $defaultDataSource) {
             $datasource->adapter = $adapter;
             $datasource->connection->dsn = $dsn;
             $datasource->connection->user = $username;
             $datasource->connection->password = $password;
         }
     }
     $config = $config->asXML();
     // Write database configuration
     if (!@file_put_contents($propelConfig, $config)) {
         $this->addMessage('Failed to write propel build configuration, please make sure this is the content of ' . $propelConfig . ':', self::MSG_ERROR);
         $this->addMainContent('<pre>' . htmlspecialchars($config) . '</pre>');
         return false;
     }
     // Generate propel classes and configuration
     $content = \Curry_Backend_DatabaseHelper::propelGen('');
     if (!\Curry_Backend_DatabaseHelper::getPropelGenStatus($content)) {
         $this->addMessage('It seems there was an error when building propel', self::MSG_ERROR);
         $this->addMainContent('<pre class="console">' . Console::colorize($content) . '</pre>');
         return false;
     }
     // Initialize propel
     \Propel::init($this->app['propel.conf']);
     // Set database charset
     if ($params['set_charset']) {
         $con = \Propel::getConnection();
         $result = $con->exec('ALTER DATABASE ' . $params['database'] . ' CHARACTER SET utf8 COLLATE utf8_general_ci');
         if (!$result) {
             $this->addMessage('Unable to change database charset', self::MSG_WARNING);
             $success = false;
         }
     }
     // Create tables
     if ($params['create_tables']) {
         $content = \Curry_Backend_DatabaseHelper::propelGen('insert-sql');
         if (!\Curry_Backend_DatabaseHelper::getPropelGenStatus($content)) {
             $this->addMessage('It seems there was an error when creating database tables', self::MSG_ERROR);
             $this->addMainContent('<pre class="console">' . Console::colorize($content) . '</pre>');
             return false;
         }
     }
     return $success;
 }
Esempio n. 4
0
 /**
  * Restore from file, using _GET request. 
  * 
  * @todo Verify this is working and that it's secure. Can we do this using session variables instead? 
  */
 public function showContinueRestore()
 {
     if (!Curry_URL::validate()) {
         throw new Exception('Invalid hash');
     }
     Curry_Backend_DatabaseHelper::restoreFromFile($_GET['file'], $_GET['tables'], $_GET['max_execution_time'], $_GET['line'], $this);
 }
Esempio n. 5
0
 /**
  * Create an automatic backup of the database.
  */
 public function doAutoBackup()
 {
     $autoBackup = Curry_Core::$config->curry->autoBackup;
     if ($autoBackup) {
         $filename = Curry_Backend_DatabaseHelper::createBackupName("backup_%Y-%m-%d_%H-%M-%S_autobackup.txt");
         $lastModified = 0;
         foreach (new DirectoryIterator(dirname($filename)) as $entry) {
             if ($entry->isFile()) {
                 $lastModified = max($lastModified, $entry->getMTime());
             }
         }
         if (time() - $lastModified >= $autoBackup && !file_exists($filename)) {
             $status = Curry_Backend_DatabaseHelper::dumpDatabase($filename);
             if ($this->backend) {
                 if ($status) {
                     $this->backend->addMessage('An automatic backup of the database has been created successfully.', Curry_Backend::MSG_SUCCESS);
                 } else {
                     $this->backend->addMessage('There was an error when trying to create the automatic backup of the database.', Curry_Backend::MSG_ERROR);
                 }
             }
         }
     }
 }