Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/Console/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
*/
namespace App\Console;

if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'r'));
}

use Cake\Codeception\Console\Installer as CodeceptionInstaller;
use Cake\Utility\Security;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use Exception;
use InvalidArgumentException;

/**
* Provides installation hooks for when this application is installed through
Expand Down Expand Up @@ -52,7 +48,7 @@ class Installer
* Does some routine installation tasks so people don't have to.
*
* @param \Composer\Script\Event $event The composer event object.
* @throws \Exception Exception raised by validator.
* @throws \InvalidArgumentException Exception raised by validator.
* @return void
*/
public static function postInstall(Event $event): void
Expand Down Expand Up @@ -124,7 +120,7 @@ public static function setFolderPermissions(string $dir, IOInterface $io): void
if (in_array($arg, ['Y', 'y', 'N', 'n'])) {
return $arg;
}
throw new Exception('This is not a valid answer. Please choose Y or n.');
throw new InvalidArgumentException('This is not a valid answer. Please choose Y or n.');
};
$setFolderPermissions = $io->askAndValidate(
'<info>Set Folder Permissions ? (Default to Y)</info> [<comment>Y,n</comment>]? ',
Expand All @@ -140,7 +136,15 @@ public static function setFolderPermissions(string $dir, IOInterface $io): void

// Change the permissions on a path and output the results.
$changePerms = function (string $path) use ($io): void {
$currentPerms = fileperms($path) & 0777;
$perms = fileperms($path);
if ($perms === false) {
// `false & 0777` would be 0 and chmod() would strip owner and group permissions.
$io->writeError('Failed to read permissions on ' . $path);

return;
}

$currentPerms = $perms & 0777;
$worldWritable = $currentPerms | 0007;
if ($worldWritable == $currentPerms) {
return;
Expand All @@ -150,7 +154,7 @@ public static function setFolderPermissions(string $dir, IOInterface $io): void
if ($res) {
$io->write('Permissions set on ' . $path);
} else {
$io->write('Failed to set permissions on ' . $path);
$io->writeError('Failed to set permissions on ' . $path);
}
};

Expand Down