コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverSection = $input->getOption('server');
     $config = new \Zend_Config_Ini('config.ini', $serverSection);
     $server = $config->server;
     $remote = ($server->port ? '-e "ssh -p ' . $server->port . '" ' : '') . $server->user . '@' . $server->host . ':' . $server->dir;
     if (!$input->getOption('dry-run')) {
         $output->writeln("This will upload the current working copy to {$remote}.");
         $output->writeln("All files will be overwritten, any changes will be lost. Online directories you don't have locally not matching a .gitignore pattern will be deleted.");
         $output->writeln("Make sure your local application is stable and build is up to date.");
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Continue with this action? [Y/n]', true);
         if (!$helper->ask($input, $output, $question)) {
             return;
         }
     }
     $excludes = ExcludeFinder::findExcludes('.');
     $excludeArgs = '';
     foreach ($excludes as $i) {
         $excludeArgs .= " --exclude=" . escapeshellarg($i);
     }
     $cmd = "rsync -apz --delete --progress --verbose ";
     if ($input->getOption('dry-run')) {
         $cmd .= "--dry-run ";
     }
     $cmd .= "{$excludeArgs} . {$remote}";
     $this->_systemCheckRet($cmd, $input, $output);
     if (!$input->getOption('dry-run')) {
         $output->writeln("Upload finished. Now executing update scripts and clearing caches.");
         $cmd = "cd {$server->dir} && " . ($server->phpCli ? $server->phpCli : 'php') . " bootstrap.php update";
         $remote = ($server->port ? '-p ' . $server->port . ' ' : '') . $server->user . '@' . $server->host;
         $cmd = "ssh {$remote} " . escapeshellarg($cmd);
         $this->_systemCheckRet($cmd, $input, $output);
     }
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!file_exists('bootstrap.php')) {
         throw new \Exception("Run this script in the application root directory");
     }
     \Kwf_Setup::setUp();
     if (file_exists('setup/initial/dump.sql')) {
         unlink('setup/initial/dump.sql');
     }
     if (file_exists('setup/initial/uploads')) {
         foreach (glob('setup/initial/uploads/*') as $f) {
             unlink($f);
         }
     }
     if ($input->getOption('include-initial-dump')) {
         $output->writeln("checking for pending updates...");
         $pendingUpdatesCount = \Kwf_Util_Update_Helper::countPendingUpdates();
         if ($pendingUpdatesCount) {
             throw new \Exception("{$pendingUpdatesCount} Updates have not been executed. Run update first.");
         }
         $output->writeln("creating database dump...");
         $dump = DbDump::dump();
         if (!file_exists('setup/initial')) {
             mkdir('setup/initial', 0777, true);
             $ignore = "";
             if (file_exists('setup/.gitignore')) {
                 $ignore = file_get_contents('setup/.gitignore');
             }
             if (!preg_match('#^initial$#m', $ignore)) {
                 $ignore = rtrim($ignore);
                 if ($ignore) {
                     $ignore .= "\n";
                 }
                 $ignore .= "initial\n";
             }
             file_put_contents('setup/.gitignore', $ignore);
         }
         file_put_contents('setup/initial/dump.sql', $dump);
         $output->writeln("copying uploads...");
         if (!file_exists('setup/initial/uploads')) {
             mkdir('setup/initial/uploads');
         }
         $model = \Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model');
         $select = new \Kwf_Model_Select();
         $it = new \Kwf_Model_Iterator_Packages(new \Kwf_Model_Iterator_Rows($model, $select));
         foreach ($it as $row) {
             $fileSource = $row->getFileSource();
             copy($fileSource, 'setup/initial/uploads/' . basename($fileSource));
         }
     }
     $excludes = ExcludeFinder::findExcludes('.');
     $excludeArgs = '';
     foreach ($excludes as $i) {
         $excludeArgs .= " -x " . escapeshellarg('./' . $i . '*');
     }
     $cmd = "zip deploy.zip . --quiet -r {$excludeArgs}";
     $output->writeln("creating deploy.zip archive...");
     $this->_systemCheckRet($cmd, $input, $output);
     $output->writeln("deploy.zip successfully created.");
 }