|
|
@ -8,15 +8,28 @@ |
|
|
|
namespace yii\composer; |
|
|
|
namespace yii\composer; |
|
|
|
|
|
|
|
|
|
|
|
use Composer\Script\CommandEvent; |
|
|
|
use Composer\Script\CommandEvent; |
|
|
|
|
|
|
|
use yii\console\Application; |
|
|
|
|
|
|
|
use yii\console\Exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defined('YII_DEBUG') or define('YII_DEBUG', true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fcgi doesn't have STDIN defined by default |
|
|
|
|
|
|
|
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* InstallHandler is called by Composer after it installs/updates the current package. |
|
|
|
* InstallHandler is called by Composer after it installs/updates the current package. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
|
|
|
|
* @author Tobias Munk <schmunk@usrbin.de> |
|
|
|
* @since 2.0 |
|
|
|
* @since 2.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class InstallHandler |
|
|
|
class InstallHandler |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const PARAM_WRITABLE = 'yii-install-writable'; |
|
|
|
|
|
|
|
const PARAM_EXECUTABLE = 'yii-install-executable'; |
|
|
|
|
|
|
|
const PARAM_CONFIG = 'yii-install-config'; |
|
|
|
|
|
|
|
const PARAM_COMMANDS = 'yii-install-commands'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the correct permissions of files and directories. |
|
|
|
* Sets the correct permissions of files and directories. |
|
|
|
* @param CommandEvent $event |
|
|
|
* @param CommandEvent $event |
|
|
@ -24,11 +37,11 @@ class InstallHandler |
|
|
|
public static function setPermissions($event) |
|
|
|
public static function setPermissions($event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$options = array_merge(array( |
|
|
|
$options = array_merge(array( |
|
|
|
'writable' => array(), |
|
|
|
self::PARAM_WRITABLE => array(), |
|
|
|
'executable' => array(), |
|
|
|
self::PARAM_EXECUTABLE => array(), |
|
|
|
), $event->getComposer()->getPackage()->getExtra()); |
|
|
|
), $event->getComposer()->getPackage()->getExtra()); |
|
|
|
|
|
|
|
|
|
|
|
foreach ((array)$options['writable'] as $path) { |
|
|
|
foreach ((array)$options[self::PARAM_WRITABLE] as $path) { |
|
|
|
echo "Setting writable: $path ..."; |
|
|
|
echo "Setting writable: $path ..."; |
|
|
|
if (is_dir($path)) { |
|
|
|
if (is_dir($path)) { |
|
|
|
chmod($path, 0777); |
|
|
|
chmod($path, 0777); |
|
|
@ -39,7 +52,7 @@ class InstallHandler |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ((array)$options['executable'] as $path) { |
|
|
|
foreach ((array)$options[self::PARAM_EXECUTABLE] as $path) { |
|
|
|
echo "Setting executable: $path ..."; |
|
|
|
echo "Setting executable: $path ..."; |
|
|
|
if (is_file($path)) { |
|
|
|
if (is_file($path)) { |
|
|
|
chmod($path, 0755); |
|
|
|
chmod($path, 0755); |
|
|
@ -50,4 +63,35 @@ class InstallHandler |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Executes a yii command. |
|
|
|
|
|
|
|
* @param CommandEvent $event |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function run($event) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$options = array_merge(array( |
|
|
|
|
|
|
|
self::PARAM_COMMANDS => array(), |
|
|
|
|
|
|
|
), $event->getComposer()->getPackage()->getExtra()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($options[self::PARAM_CONFIG])) { |
|
|
|
|
|
|
|
throw new Exception('Please specify the "' . self::PARAM_CONFIG . '" parameter in composer.json.'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$configFile = getcwd() . '/' . $options[self::PARAM_CONFIG]; |
|
|
|
|
|
|
|
if (!is_file($configFile)) { |
|
|
|
|
|
|
|
throw new Exception("Config file does not exist: $configFile"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require(__DIR__ . '/../../../yii2/yii/Yii.php'); |
|
|
|
|
|
|
|
$application = new Application(require($configFile)); |
|
|
|
|
|
|
|
$request = $application->getRequest(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ((array)$options[self::PARAM_COMMANDS] as $command) { |
|
|
|
|
|
|
|
$params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573 |
|
|
|
|
|
|
|
$request->setParams($params); |
|
|
|
|
|
|
|
list($route, $params) = $request->resolve(); |
|
|
|
|
|
|
|
echo "Running command: yii {$command}\n"; |
|
|
|
|
|
|
|
$application->runAction($route, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|