Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions .vortex/installer/src/Command/DestinationAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DrevOps\VortexInstaller\Command;

use DrevOps\VortexInstaller\Utils\File;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -42,13 +43,13 @@ protected function getDestination(InputInterface $input): string {
throw new \InvalidArgumentException('Destination must be a string.');
}

if (!is_dir($destination)) {
if (!File::isDir($destination)) {
throw new \InvalidArgumentException(
sprintf('Destination directory does not exist: %s', $destination)
);
}

return realpath($destination) ?: $destination;
return File::realpath($destination);
}

}
4 changes: 2 additions & 2 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function handleValidate(InputInterface $input, OutputInterface $output
return Command::FAILURE;
}

$prompts_json = is_file($prompts_option) ? (string) file_get_contents($prompts_option) : $prompts_option;
$prompts_json = OptionsResolver::readJsonOption($prompts_option, '--prompts');
$decoded = json_decode($prompts_json);

if (!$decoded instanceof \stdClass) {
Expand Down Expand Up @@ -437,7 +437,7 @@ public function cleanup(): void {
}

$phar_path = \Phar::running(FALSE);
if (!empty($phar_path) && file_exists($phar_path)) {
if (!empty($phar_path) && File::exists($phar_path)) {
File::remove($phar_path);
}
}
Expand Down
8 changes: 4 additions & 4 deletions .vortex/installer/src/Downloader/Archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public function detectFormat(string $archive_path): ?string {
* {@inheritdoc}
*/
public function validate(string $archive_path): void {
if (!file_exists($archive_path)) {
if (!File::exists($archive_path)) {
throw new \RuntimeException(sprintf('Archive file does not exist: "%s".', $archive_path));
}

if (filesize($archive_path) === 0) {
if (File::size($archive_path) === 0) {
throw new \RuntimeException('Archive is empty.');
}

Expand Down Expand Up @@ -125,7 +125,7 @@ protected function extractTar(string $archive_path, string $destination, bool $s
throw new \RuntimeException(sprintf('Unable to extract tar archive to "%s": %s.', $destination, $e->getMessage()), $e->getCode(), $e);
}
finally {
if ($strip_first_level && is_dir($temp_dir)) {
if ($strip_first_level && File::isDir($temp_dir)) {
File::remove($temp_dir);
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ protected function extractZip(string $archive_path, string $destination, bool $s
throw new \RuntimeException(sprintf('Unable to extract ZIP archive to "%s": %s.', $destination, $e->getMessage()), $e->getCode(), $e);
}
finally {
if ($strip_first_level && is_dir($temp_dir)) {
if ($strip_first_level && File::isDir($temp_dir)) {
File::remove($temp_dir);
}
}
Expand Down
54 changes: 30 additions & 24 deletions .vortex/installer/src/Downloader/RepositoryDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function download(Artifact $artifact, ?string $destination = NULL, ?strin
$version = $this->downloadFromLocal($artifact, $destination);
}

if (!is_readable($destination . '/composer.json')) {
if (!File::isReadable($destination . '/composer.json')) {
throw new \RuntimeException('The downloaded repository does not contain a composer.json file.');
}

Expand Down Expand Up @@ -130,9 +130,15 @@ protected function downloadFromRemote(Artifact $artifact, ?string $destination,
$url = sprintf(self::ARCHIVE_URL_TEMPLATE, $repo_url, $ref);

$archive_path = $this->downloadArchive($url);
$this->archiver->validate($archive_path);
$this->archiver->extract($archive_path, $destination, TRUE);
File::remove($archive_path);

try {
$this->archiver->validate($archive_path);
$this->archiver->extract($archive_path, $destination, TRUE);
}
finally {
// The archive is created inside a temporary directory of its own.
File::remove(dirname($archive_path));
}

return $version;
}
Expand All @@ -159,9 +165,15 @@ protected function downloadFromLocal(Artifact $artifact, ?string $destination):
}

$archive_path = $this->archiveFromLocal($artifact->getRepo(), $ref);
$this->archiver->validate($archive_path);
$this->archiver->extract($archive_path, $destination, FALSE);
File::remove($archive_path);

try {
$this->archiver->validate($archive_path);
$this->archiver->extract($archive_path, $destination, FALSE);
}
finally {
// The archive is created inside a temporary directory of its own.
File::remove(dirname($archive_path));
}

return $version;
}
Expand All @@ -177,7 +189,6 @@ protected function discoverLatestReleaseRemote(string $repo_url, ?string $releas
$release_url = sprintf('https://api.github.com/repos/%s/releases', $path);

$headers = self::requestHeaders($release_url, ['Accept' => 'application/vnd.github.v3+json']);
$github_token = Env::get('GITHUB_TOKEN');

try {
$response = $this->httpClient->request('GET', $release_url, ['headers' => $headers]);
Expand All @@ -188,7 +199,7 @@ protected function discoverLatestReleaseRemote(string $repo_url, ?string $releas
}

if ($release_contents === '' || $release_contents === '0') {
$message = sprintf('Unable to download release information from "%s"%s.', $release_url, $github_token ? ' (GitHub token was used)' : '');
$message = sprintf('Unable to download release information from "%s"%s.', $release_url, isset($headers['Authorization']) ? ' (GitHub token was used)' : '');
throw new \RuntimeException($message);
}

Expand Down Expand Up @@ -219,18 +230,14 @@ protected function discoverLatestReleaseRemote(string $repo_url, ?string $releas
* If download fails.
*/
protected function downloadArchive(string $url): string {
$temp_file = tempnam(sys_get_temp_dir(), 'vortex_archive_');
if ($temp_file === FALSE) {
throw new \RuntimeException('Unable to create temporary file for archive download.');
}
$temp_dir = File::tmpdir(prefix: 'vortex_archive_');
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . 'archive.tar.gz';

try {
$this->fileDownloader->download($url, $temp_file, self::requestHeaders($url));
}
catch (\RuntimeException $e) {
if (file_exists($temp_file)) {
File::remove($temp_file);
}
File::remove($temp_dir);
throw new \RuntimeException(sprintf('Unable to download archive from "%s": %s.', $url, $e->getMessage()), $e->getCode(), $e);
}

Expand All @@ -256,19 +263,18 @@ protected function archiveFromLocal(string $repo, string $ref): string {
$this->git = new Git($repo);
}

$temp_file = sys_get_temp_dir() . '/vortex_local_archive_' . uniqid() . '.tar';
$temp_dir = File::tmpdir(prefix: 'vortex_local_archive_');
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . 'archive.tar';

try {
$this->git->run('archive', '--format=tar', $ref, '-o', $temp_file);

if (!file_exists($temp_file) || filesize($temp_file) === 0) {
if (!File::exists($temp_file) || File::size($temp_file) === 0) {
throw new \RuntimeException('Archive creation produced empty file.');
}
}
catch (\Exception $e) {
if (file_exists($temp_file)) {
File::remove($temp_file);
}
File::remove($temp_dir);
throw new \RuntimeException(sprintf('Unable to create archive from local repository "%s": %s.', $repo, $e->getMessage()), $e->getCode(), $e);
}

Expand Down Expand Up @@ -342,11 +348,11 @@ protected function validateRemoteRefExists(string $repo_url, string $ref): void
* If the repository does not exist or is not a valid git repository.
*/
protected function validateLocalRepositoryExists(string $repo): void {
if (!is_dir($repo)) {
if (!File::isDir($repo)) {
throw new \RuntimeException(sprintf('Local repository path does not exist: "%s".', $repo));
}

if (!is_dir($repo . '/.git')) {
if (!File::isDir($repo . '/.git')) {
throw new \RuntimeException(sprintf('Path is not a git repository: "%s".', $repo));
}
}
Expand All @@ -363,7 +369,7 @@ protected function validateLocalRepositoryExists(string $repo): void {
* If the reference does not exist.
*/
protected function validateLocalRefExists(string $repo, string $ref): void {
$repo_path = (string) realpath($repo);
$repo_path = File::realpath($repo);

if (!$this->git instanceof Git || $this->git->getRepositoryPath() !== $repo_path) {
$this->git = new Git($repo);
Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Logger/FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function open(string $command, array $args = []): bool {
$this->path = $this->getDir() . '/' . self::LOG_DIR . '/' . $name . '-' . date('Y-m-d-His') . '.log';

$log_dir = dirname($this->path);
if (!is_dir($log_dir)) {
if (!File::isDir($log_dir)) {
File::mkdir($log_dir);
}

Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Prompts/Handlers/AssignAuthorPr.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function discover(): null|string|bool|array {
return NULL;
}

return file_exists($this->destinationDir . '/.github/workflows/assign-author.yml');
return File::exists($this->destinationDir . '/.github/workflows/assign-author.yml');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions .vortex/installer/src/Prompts/Handlers/CiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public function discover(): null|string|bool|array {
return NULL;
}

if (is_readable($this->destinationDir . '/.github/workflows/build-test-deploy.yml')) {
if (File::exists($this->destinationDir . '/.github/workflows/build-test-deploy.yml')) {
return self::GITHUB_ACTIONS;
}

if (is_readable($this->destinationDir . '/.circleci/config.yml')) {
if (File::exists($this->destinationDir . '/.circleci/config.yml')) {
return self::CIRCLECI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function discover(): null|string|bool|array {

$gha_files = glob($this->destinationDir . '/.github/workflows/*.{yml,yaml}', GLOB_BRACE) ?: [];
foreach ($gha_files as $gha_file) {
if (is_readable($gha_file) && File::contains($gha_file, 'codecov/codecov-action')) {
if (File::contains($gha_file, 'codecov/codecov-action')) {
return self::CODECOV;
}
}

$circle = $this->destinationDir . '/.circleci/config.yml';
if (is_readable($circle) && File::contains($circle, 'codecov -Z -s')) {
if (File::contains($circle, 'codecov -Z -s')) {
return self::CODECOV;
}

Expand Down
8 changes: 4 additions & 4 deletions .vortex/installer/src/Prompts/Handlers/CodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function default(array $responses): null|string|bool|array {
* {@inheritdoc}
*/
public function discover(): null|string|bool|array {
if (file_exists($this->destinationDir . '/.github')) {
if (File::exists($this->destinationDir . '/.github')) {
return self::GITHUB;
}

return $this->isInstalled() && file_exists($this->destinationDir . '/.git') ? self::OTHER : NULL;
return $this->isInstalled() && File::exists($this->destinationDir . '/.git') ? self::OTHER : NULL;
}

/**
Expand All @@ -71,8 +71,8 @@ public function process(): void {
if ($v === self::GITHUB) {
File::remove($t . '/.github/PULL_REQUEST_TEMPLATE.md');

if (file_exists($t . '/.github/PULL_REQUEST_TEMPLATE.dist.md')) {
rename($t . '/.github/PULL_REQUEST_TEMPLATE.dist.md', $t . '/.github/PULL_REQUEST_TEMPLATE.md');
if (File::exists($t . '/.github/PULL_REQUEST_TEMPLATE.dist.md')) {
File::rename($t . '/.github/PULL_REQUEST_TEMPLATE.dist.md', $t . '/.github/PULL_REQUEST_TEMPLATE.md');
}
}
else {
Expand Down
8 changes: 4 additions & 4 deletions .vortex/installer/src/Prompts/Handlers/CustomModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public function discover(): null|string|bool|array {

$module_dir = $this->destinationDir . '/' . $this->webroot . '/modules/custom';

if (is_dir($module_dir . '/' . $prefix . '_base')) {
if (File::isDir($module_dir . '/' . $prefix . '_base')) {
$modules[] = self::BASE;
}

if (is_dir($module_dir . '/' . $prefix . '_demo')) {
if (File::isDir($module_dir . '/' . $prefix . '_demo')) {
$modules[] = self::DEMO;
}

if (is_dir($module_dir . '/' . $prefix . '_search')) {
if (File::isDir($module_dir . '/' . $prefix . '_search')) {
$modules[] = self::SEARCH;
}

Expand Down Expand Up @@ -220,7 +220,7 @@ protected function discoverModulePrefix(): ?string {
protected static function removeDemoBehatFeatures(string $dir): void {
$features_dir = $dir . '/tests/behat/features';

if (!is_dir($features_dir)) {
if (!File::isDir($features_dir)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function discover(): null|string|bool|array {
return NULL;
}

if (!is_readable($this->destinationDir . '/renovate.json')) {
if (!File::exists($this->destinationDir . '/renovate.json')) {
return self::NONE;
}

if (file_exists($this->destinationDir . '/.github/workflows/update-dependencies.yml')) {
if (File::exists($this->destinationDir . '/.github/workflows/update-dependencies.yml')) {
return self::RENOVATEBOT_CI;
}

Expand Down
3 changes: 2 additions & 1 deletion .vortex/installer/src/Prompts/Handlers/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace DrevOps\VortexInstaller\Prompts\Handlers;

use DrevOps\VortexInstaller\Utils\Env;
use DrevOps\VortexInstaller\Utils\File;

class Dotenv extends AbstractHandler {

Expand All @@ -22,7 +23,7 @@ public function discover(): null|string|bool|array {
public function process(): void {
$t = $this->tmpDir;

if (is_readable($this->destinationDir . '/.env')) {
if (File::exists($this->destinationDir . '/.env')) {
$variables = Env::parseDotenv($this->destinationDir . '/.env');
foreach ($variables as $name => $value) {
Env::writeValueDotenv($name, $value, $t . '/.env');
Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Prompts/Handlers/Gitleaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function discover(): null|string|bool|array {
return NULL;
}

return file_exists($this->destinationDir . '/.gitleaks.toml');
return File::exists($this->destinationDir . '/.gitleaks.toml');
}

/**
Expand Down
12 changes: 6 additions & 6 deletions .vortex/installer/src/Prompts/Handlers/HostingProjectName.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function discover(): null|string|bool|array {
// instead of a hardcoded project name. Kept for backward compatibility
// with older installations.
$acquia_settings_file = $this->destinationDir . sprintf('/%s/sites/default/includes/providers/settings.acquia.php', $this->webroot);
if (file_exists($acquia_settings_file)) {
$content = file_get_contents($acquia_settings_file);
if (File::isReadable($acquia_settings_file)) {
$content = File::read($acquia_settings_file);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Require '/var/www/site-php/your_site/your_site-settings.inc';.
if ($content !== FALSE && preg_match('/require\s+[\'"]\/var\/www\/site-php\/([a-z0-9_]+)\/[a-z0-9_]+-settings\.inc[\'"]\s*;/', $content, $matches) && !empty($matches[1])) {
if (preg_match('/require\s+[\'"]\/var\/www\/site-php\/([a-z0-9_]+)\/[a-z0-9_]+-settings\.inc[\'"]\s*;/', $content, $matches) && !empty($matches[1])) {
return $matches[1];
}
}
Expand All @@ -95,9 +95,9 @@ public function discover(): null|string|bool|array {
}

$lagoon_site_file = $this->destinationDir . '/drush/sites/lagoon.site.yml';
if (file_exists($lagoon_site_file)) {
$content = file_get_contents($lagoon_site_file);
if ($content !== FALSE && preg_match('/user:\s*([a-z0-9_]+)-/', $content, $matches) && (!empty($matches[1]) && $matches[1] !== 'your_site')) {
if (File::isReadable($lagoon_site_file)) {
$content = File::read($lagoon_site_file);
if (preg_match('/user:\s*([a-z0-9_]+)-/', $content, $matches) && (!empty($matches[1]) && $matches[1] !== 'your_site')) {
return $matches[1];
}
}
Expand Down
4 changes: 2 additions & 2 deletions .vortex/installer/src/Prompts/Handlers/HostingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function default(array $responses): null|string|bool|array {
* {@inheritdoc}
*/
public function discover(): null|string|bool|array {
if (is_readable($this->destinationDir . '/hooks') || Env::getFromDotenv('VORTEX_FETCH_DB_SOURCE', $this->destinationDir) === DatabaseFetchSource::ACQUIA) {
if (File::exists($this->destinationDir . '/hooks') || Env::getFromDotenv('VORTEX_FETCH_DB_SOURCE', $this->destinationDir) === DatabaseFetchSource::ACQUIA) {
return self::ACQUIA;
}

if (is_readable($this->destinationDir . '/.lagoon.yml')) {
if (File::exists($this->destinationDir . '/.lagoon.yml')) {
return self::LAGOON;
}

Expand Down
Loading