/**
* Constructor.
*
* Searches all installed applications and libraries for migration
* directories and builds lists of migrateable modules and directories.
*
* @param string $basedir Base directory of a Git checkout. If provided
* a framework/ sub directory is searched for
* migration scripts too.
* @param string $pearconf Path to a PEAR configuration file.
*/
public function __construct($basedir = null, $pearconf = null)
{
// Loop through all applications.
foreach ($GLOBALS['registry']->listAllApps() as $app) {
$dir = $GLOBALS['registry']->get('fileroot', $app) . '/migration';
if (is_dir($dir)) {
$this->apps[] = $app;
$this->_lower[] = Horde_String::lower($app);
$this->dirs[] = realpath($dir);
}
}
// Silence PEAR errors.
$old_error_reporting = error_reporting();
error_reporting($old_error_reporting & ~E_DEPRECATED);
$pear = new PEAR_Config($pearconf);
// Loop through local framework checkout.
if ($basedir) {
$packageFile = new PEAR_PackageFile($pear);
foreach (glob($basedir . '/framework/*/migration') as $dir) {
$package = $packageFile->fromPackageFile(dirname($dir) . '/package.xml', PEAR_VALIDATE_NORMAL);
if ($package instanceof PEAR_Error) {
Horde::log(sprintf('%s: %s', $package->getMessage(), print_r($package->getUserInfo(), true)), Horde_Log::ERR);
continue;
}
$this->apps[] = $package->getName();
$this->_lower[] = Horde_String::lower($package->getName());
$this->dirs[] = realpath($dir);
}
}
// Loop through installed PEAR packages.
$registry = $pear->getRegistry();
foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) {
$package = $registry->getPackage(basename(dirname($dir)), 'pear.horde.org');
if ($package == false) {
Horde::log("Ignoring package in directory {$dir}", Horde_Log::WARN);
continue;
}
$app = $package->getName();
if (!in_array($app, $this->apps)) {
$this->apps[] = $app;
$this->_lower[] = Horde_String::lower($app);
$this->dirs[] = realpath($dir);
}
}
error_reporting($old_error_reporting);
}