-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This install script takes care of copying the default config file into its proper place, and changing permissions on the tmp dir if required. This will help ease use of the app skeleton. It also gives a place for application developers to provide their own install script if they want.
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* PHP 5 | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since CakePHP(tm) v 3.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace App\Console; | ||
|
||
use Composer\Script\Event; | ||
|
||
/** | ||
* Provides installation hooks for when this application is installed via | ||
* composer. Customize this class to suit your needs. | ||
*/ | ||
class Installer { | ||
|
||
/** | ||
* Does some routine installation tasks so people don't have to. | ||
* | ||
* @param Composer\Script\Event $event | ||
*/ | ||
public static function postInstall(Event $event) { | ||
$io = $event->getIO(); | ||
|
||
$rootDir = dirname(dirname(__DIR__)); | ||
static::createAppConfig($rootDir, $io); | ||
static::setTmpPermissions($rootDir, $io); | ||
|
||
} | ||
|
||
/** | ||
* Create the Config/app.php file if it does not exist. | ||
* | ||
* @param string $dir The application's root directory. | ||
* @param Composer\IO\IOInterface IO interface to write to console. | ||
* @return void | ||
*/ | ||
public static function createAppConfig($dir, $io) { | ||
$appConfig = $dir . '/App/Config/app.php'; | ||
$defaultConfig = $dir . '/App/Config/app.php.default'; | ||
if (!file_exists($appConfig)) { | ||
copy($defaultConfig, $appConfig); | ||
$io->write('Created `Config/app.php` file'); | ||
} | ||
} | ||
|
||
/** | ||
* Set globally writable permissions on the tmp directory. | ||
* | ||
* This is not the most secure default, but it gets people up and running quickly. | ||
* | ||
* @param string $dir The application's root directory. | ||
* @param Composer\IO\IOInterface IO interface to write to console. | ||
* @return void | ||
*/ | ||
public static function setTmpPermissions($dir, $io) { | ||
$worldWritable = bindec('0110000000'); | ||
|
||
// Get current permissions in decimal format so we can bitmask it. | ||
$currentPerms = octdec(substr(sprintf('%o', fileperms($dir . '/tmp')), -4)); | ||
|
||
if (($currentPerms & $worldWritable) != $worldWritable) { | ||
$io->write('Attempting to set permissions on tmp/'); | ||
$result = chmod('./tmp', $currentPerms | $worldWritable); | ||
if ($result) { | ||
$io->write('Permissions set on tmp/'); | ||
} else { | ||
$io->write('Failed to set permissions on tmp/ you must do it yourself.'); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters