Exemplo 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();
 }
Exemplo n.º 2
0
 /**
  * Show view to unpack bundle.
  */
 protected static function showUnpack()
 {
     echo '<div id="unpack">';
     echo '<h2>Select bundle</h2>';
     $bundles = glob('*.tar');
     if ($bundles === false) {
         if (!is_readable('bundle.tar')) {
             echo '<div class="error"><p>Failed to scan directory for bundle files, please name the file bundle.tar for successful detection.</p></div>';
         }
         $bundles = array('bundle.tar');
     }
     if (!count($bundles)) {
         echo '<p>Please upload your bundle file to the same folder as this script (install.php). You should then be able to select your bundle for unpacking if you reload the page.</p>';
     } else {
         if (!isset($_POST['bundle'])) {
             echo '<p>The selected bundle will be unpacked to this directory, no files will be overwritten.';
             echo '<form action="" method="POST">';
             $options = '';
             foreach ($bundles as $bundle) {
                 $options .= '<option value="' . htmlspecialchars($bundle) . '">' . htmlspecialchars($bundle) . '</option>';
             }
             echo '<select name="bundle">' . $options . '</select><br/>';
             echo '<input class="button unpack-button" type="submit" name="unpack" value="Unpack" /><br/>';
             echo '</form>';
         } else {
             echo "<p>Extracting files...</p>";
             $bundle = $_POST['bundle'];
             if (!in_array($bundle, $bundles)) {
                 echo '<div class="error"><p>Invalid bundle name.</p></div>';
                 return;
             }
             @set_time_limit(300);
             $symlinkFallback = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' || !function_exists('symlink');
             $symlinks = array();
             $tar = new Archive($bundle);
             $tar->extract(array(array('callback' => function ($file, $options) use(&$symlinks, $symlinkFallback) {
                 if ($file->isLink() && $symlinkFallback) {
                     $symlinks[] = $file;
                     return false;
                 }
                 return true;
             }, 'overwrite' => function ($file, $options) {
                 echo "Warning, file {$file->getPathname()} already exists, skipping<br />";
                 return false;
             }), array('path' => 'www/', 'target' => './')));
             self::fixSymlinks($symlinks);
             echo '<div class="success"><p>Bundle unpacked successfully.</p></div>';
             $success = self::writeInit();
             $success = self::writeConfig() && $success;
             if ($success) {
                 echo '<div class="success"><p>Curry configuration written.</p></div>';
             }
             echo '<p><a href="admin.php">Continue setup</a>.</p>';
         }
     }
     echo '</div>';
 }