<?php
/**
* Runs during composer execution to help keep our Core library in same space as project.
*
* If initial run, everything proceeds and normal, and then vendor/mytrus/Core
* is moved to src/Mytrus/Core.
*
* If previously run, or src/Mytrus/Core already exists, nothing is overwritten.
*
* Also overwrites the default phpunit bin file in vendor/bin/phpunit to fix some
* issues.
*
* Last Commit Date: $Date: 2014-01-23 10:41:47 -0800 (Thu, 23 Jan 2014) $
* Revision: $Revision: 14411 $
* Author: $Author: jtreminio $
* File: $HeadURL: https://jira.mytrus.com/svn/ODY/trunk/site/src/Mytrus/Installer.php $
*
* @copyright Copyright (c) 2013 Mytrus, Inc. (http://www.mytrus.com)
*/
namespace Mytrus;
use Composer\Script\Event;
abstract class Installer
{
static private $initialInstall = false;
static public function postInstall(Event $event)
{
$twigCache = __DIR__ . '/../../twig.cache';
if (!is_dir($twigCache)) {
if (!mkdir($twigCache, 0777)) {
throw new \Exception('Twig cache directory could not be created');
}
}
if (!is_writable($twigCache)) {
if (!chmod($twigCache, 0777)) {
throw new \Exception('Twig cache directory could not be made writable');
}
}
$vendorDir = realpath($event->getComposer()->getConfig()->get('vendor-dir'));
$baseDir = $vendorDir . '/../';
$coreRepoLoc = $baseDir . 'src/Mytrus/Core';
if (is_dir($coreRepoLoc)) {
$event->getIO()->write(
"<warning>Core exists at {$coreRepoLoc} and will not be overwritten.</warning>"
);
$vendorPhpunit = "{$vendorDir}/bin/phpunit";
if (is_link($vendorPhpunit) || !is_file($vendorPhpunit)) {
$event->getIO()->write(
"<warning>Replacing the vendor-provided phpunit bin</warning>"
);
shell_exec("rm -f {$vendorPhpunit} && cp -f {$coreRepoLoc}/Config/bin/phpunit {$vendorPhpunit}");
}
return;
}
static::$initialInstall = true;
shell_exec("mv {$vendorDir}/mytrus/core {$coreRepoLoc}");
}
/**
* @param Event $event
*
* @throws \Exception when extra configuration is not defined properly
*/
static public function preUpdate(Event $event)
{
$vendorDir = realpath($event->getComposer()->getConfig()->get('vendor-dir'));
$baseDir = $vendorDir . '/../';
$coreRepoLoc = $baseDir . 'src/Mytrus/Core';
// Only throw exception if this isn't an initial $ composer install
if (is_dir($coreRepoLoc) && !static::$initialInstall) {
$event->getIO()->write(
"<warning>Core exists at {$coreRepoLoc} and will not be overwritten.</warning>"
);
}
}
}