public function __construct(Symfony_Process_Process $process) { if ($process->isSuccessful()) { throw new Symfony_Process_Exception_InvalidArgumentException('Expected a failed process, but the given process was successful.'); } $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText()); if (!$process->isOutputDisabled()) { $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput()); } parent::__construct($error); $this->process = $process; }
private function backupRootFiles($compressionLevel, $backupFile, $exclude) { $zip = mwp_container()->getExecutableFinder()->find('zip', 'zip'); $arguments = array($zip, '-q', '-j', '-' . $compressionLevel, $backupFile); $fileExclusions = array('../', 'error_log'); foreach ($exclude as $exclusion) { if (is_file(ABSPATH . $exclusion)) { $fileExclusions[] = $exclusion; } } $parentWpConfig = ''; if (!file_exists(ABSPATH . 'wp-config.php') && file_exists(dirname(ABSPATH) . '/wp-config.php') && !file_exists(dirname(ABSPATH) . '/wp-settings.php')) { $parentWpConfig = '../wp-config.php'; } $command = implode(' ', array_map(array('Symfony_Process_ProcessUtils', 'escapeArgument'), $arguments)) . " .* ./* {$parentWpConfig}"; if ($fileExclusions) { $command .= ' ' . implode(' ', array_map(array('Symfony_Process_ProcessUtils', 'escapeArgument'), array_merge(array('-x'), $fileExclusions))); } try { if (!mwp_is_shell_available()) { throw new MMB_Exception("Shell is not available"); } $process = new Symfony_Process_Process($command, untrailingslashit(ABSPATH), null, null, 3600); mwp_logger()->debug('Root files compression process started', array('executable_location' => $zip, 'command_line' => $process->getCommandLine())); $process->start(); while ($process->isRunning()) { sleep(1); echo " "; flush(); mwp_logger()->debug('Compressing...'); } if ($process->isSuccessful()) { mwp_logger()->info('Root files compression process finished'); } elseif ($process->getExitCode() === 18) { mwp_logger()->notice('Root files compression process finished with warnings; some files could not be read', array('process' => $process)); } else { throw new Symfony_Process_Exception_ProcessFailedException($process); } } catch (Symfony_Process_Exception_ProcessFailedException $e) { mwp_logger()->error('Root files compression process failed', array('process' => $e->getProcess())); throw $e; } catch (Exception $e) { mwp_logger()->error('Error while trying to execute root files compression process', array('exception' => $e)); throw $e; } }