public function linkPackageFromSource($package, $reason = '')
{
$this->_output->ok(sprintf('About to symlink package %s%s', $package, $reason));
ob_start();
$warnings = array();
$pkg = $this->_factory->createPackageForEnvironment($package, $this);
$destDir = array('horde' => $this->getPearConfig()->get('horde_dir', 'user', 'pear.horde.org'), 'php' => $this->getPearConfig()->get('php_dir'), 'data' => $this->getPearConfig()->get('data_dir') . '/' . $pkg->getName(), 'script' => $this->getPearConfig()->get('bin_dir'));
$dir = dirname($package);
foreach ($pkg->getInstallationFilelist() as $file) {
$orig = realpath($dir . '/' . $file['attribs']['name']);
if (empty($orig)) {
$warnings[] = 'Install file does not seem to exist: ' . $dir . '/' . $file['attribs']['name'];
continue;
}
switch ($file['attribs']['role']) {
case 'horde':
case 'php':
case 'data':
case 'script':
if (isset($file['attribs']['install-as'])) {
$dest = $destDir[$file['attribs']['role']] . '/' . $file['attribs']['install-as'];
} elseif (isset($file['attribs']['baseinstalldir'])) {
$dest = $destDir[$file['attribs']['role']] . $file['attribs']['baseinstalldir'] . '/' . $file['attribs']['name'];
} else {
$dest = $destDir[$file['attribs']['role']] . '/' . $file['attribs']['name'];
}
break;
default:
$dest = null;
break;
}
if (!is_null($dest)) {
if (file_exists($dest)) {
@unlink($dest);
} elseif (!file_exists(dirname($dest))) {
@mkdir(dirname($dest), 0777, true);
}
print 'SYMLINK: ' . $orig . ' -> ' . $dest . "\n";
if (!symlink($orig, $dest)) {
$warnings[] = 'Could not link ' . $orig . '.';
}
}
}
$this->_output->pear(ob_get_clean());
foreach ($warnings as $warning) {
$this->_output->warn($warning);
}
$this->_output->ok(sprintf('Successfully symlinked package %s%s', $package, $reason));
}