Skip to content

Instantly share code, notes, and snippets.

@radmiraal
Created August 3, 2012 10:36
Show Gist options
  • Save radmiraal/3246598 to your computer and use it in GitHub Desktop.
Save radmiraal/3246598 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL ^ E_STRICT);
ini_set('display_errors', 1);
class FetchHandler {
/**
* @var string The path to this script
*/
protected $rootPath;
/**
* @var string The path to the FLOW3 project root folder
*/
protected $projectPath;
/**
* @var array List of command files to process
*/
protected $commandFiles = array();
/**
* Construct the FetchHandler
*/
public function __construct() {
$this->projectPath = realpath(getenv('WORKSPACE') ? getenv('WORKSPACE') : $_SERVER['PWD']) . DIRECTORY_SEPARATOR;
$this->rootPath = $this->projectPath . implode(DIRECTORY_SEPARATOR, array('Build', 'QueuedPatches')) . DIRECTORY_SEPARATOR;
}
/**
* Fetch all command files and process them
* @return void
*/
public function fetch() {
$this->getCommandFiles($this->rootPath);
foreach ($this->commandFiles as $commandFile) {
$packageDirectory = $this->projectPath . str_replace($this->rootPath, '', $commandFile);
echo $packageDirectory . chr(10);
if (is_dir($packageDirectory)) {
$this->patchPackage($packageDirectory, $commandFile);
}
}
}
public function patchPackage($path, $commandFile) {
echo $path . chr(10);
$commands = explode(chr(13), file_get_contents($commandFile));
foreach ($commands as $command) {
if (trim($command) === '') {
continue;
}
$cmd = sprintf('cd %s && %s', $path, $command);
echo exec($cmd);
}
}
/**
* Recursively fetch all command files in a given path
* @param $path
* @return void
*/
protected function getCommandFiles($path) {
$files = $this->getDirectoryContent($path);
foreach ($files as $file) {
if (is_dir($file)) {
$this->getCommandFiles($file . '/');
} else {
$this->commandFiles[] = $file;
}
}
}
/**
* Get all files and directories in a given path
*
* @param $path
* @return array
*/
protected function getDirectoryContent($path) {
$content = array();
if (is_dir($path)) {
$directoryIterator = new DirectoryIterator($path);
foreach ($directoryIterator as $entry) {
if (!$entry->isDot()) {
$content[] = $entry->getPathname();
}
}
}
return $content;
}
}
/**
* Initialize the handler and fetch all changes
*/
$handler = new FetchHandler();
$handler->fetch();
?>
@radmiraal
Copy link
Author

Needs a folder:

Build/QueuedPatches/

below you can make a structure like /path/to/submodule/parent/ which contains shell commands to be executed on every line (I use cherry-pick commands from gerrit here)

So if you have a patch for TYPO3.FLOW3 you copy the cherry-pick command for it, and paste it in a file named:

Build/QueuedPatches/Packages/Framework/TYPO3.FLOW3 (no further file extension)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment