/** * Returns incremental process output (even if empty string) or false if the process has finished * successfully and all output was already returned. * * @throws Symfony_Process_Exception_ProcessFailedException If the process did not exit successfully. * * @internal * * @return string|false */ public function getIncrementalOutput() { if (!$this->ran) { $this->ran = true; try { $this->process->start(); } catch (Symfony_Process_Exception_ExceptionInterface $e) { throw new Symfony_Process_Exception_ProcessFailedException($this->process); } } if ($this->process->isRunning()) { $output = $this->process->getIncrementalOutput(); $this->process->clearOutput(); if (strlen($output) < Symfony_Process_Pipes_PipesInterface::CHUNK_SIZE) { // Don't hog the processor while waiting for incremental process output. usleep(100000); } // The stream will be read again because we're returning a string. return (string) $output; } else { if (!$this->process->isSuccessful()) { throw new Symfony_Process_Exception_ProcessFailedException($this->process); } $output = $this->process->getIncrementalOutput(); $this->process->clearOutput(); // The process has finished and is successful. This part will probably get run twice, // first time we'll return final output, second time we'll return 'false' and break the loop. return strlen($output) ? $output : false; } }
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; } }