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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ Homestead.yaml
npm-debug.log
Thumbs.db
yarn-error.log
/archive/*
/storage/packages/*/
/storage/packages/*
/storage/packages/*/*/*.zip
/storage/packages/*/*
/storage/downloads/*.zip
/storage/archive
64 changes: 64 additions & 0 deletions app/Console/Commands/ClearDownloadedAndStoredPackagesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Console\Commands;

use App\Models\Package;
use App\Models\Version;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Filesystem\FilesystemManager;

class ClearDownloadedAndStoredPackagesCommand extends Command
{
protected $signature = 'packages:clear';

protected $description = 'Clears the downloaded cache of stored packages and their versions.';

public function handle(FilesystemManager $manager)
{
$filesystem = $manager->disk('app');

if (!$filesystem->deleteDirectory('storage/archive')) {
$this->error('Failed to clear the archive directory. It may not exist.');
return;
}

if ($filesystem->exists('storage/archive')) {
$this->error('Failed to delete the archive directory. It may not be empty or there may be permission issues.');
return;
}

if (!$filesystem->makeDirectory('storage/archive')) {
$this->error('Failed to recreate the archive directory.');
return;
}
$this->info('Cleared the archive directory.');

if (!$filesystem->delete($filesystem->files('storage/downloads'))) {
$this->error('Failed to clear the downloads directory. It may not exist.');
return;
}
if (!$filesystem->makeDirectory('storage/downloads')) {
$this->error('Failed to recreate the downloads directory.');
return;
}
$this->info('Cleared the downloads directory.');

if (!$filesystem->deleteDirectory('storage/packages')) {
$this->error('Failed to clear the packages directory. It may not exist.');
return;
}
if (!$filesystem->makeDirectory('storage/packages')) {
$this->error('Failed to recreate the packages directory.');
return;
}
$this->info('Cleared the packages directory.');

Version::truncate()->get();
$this->info('Cleared all versions from the database.');
Package::truncate()->get();
$this->info('Cleared all packages from the database.');
$this->info('All downloaded and stored packages have been cleared successfully.');

}
}
96 changes: 10 additions & 86 deletions app/Console/Commands/ExtraProcessingForPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace App\Console\Commands;

use App\Jobs\RepackageVersionInZipJob;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Symfony\Component\Process\Process;
use Illuminate\Support\Facades\Bus;

class ExtraProcessingForPackagesCommand extends Command
{
Expand All @@ -15,95 +14,20 @@ class ExtraProcessingForPackagesCommand extends Command

public function handle()
{
$jobs = [];
$page = 1;
$filesystem = new Filesystem();
do {
$packages = \App\Models\Package::query()
->where('needs_additional_processing', true)
->whereNotIn('name', [
'winter/wn-backend-module',
'winter/wn-cms-module',
])
->paginate(page: $page, perPage: 100);

->where('code', 'later')
->paginate(perPage: 100, page: $page++);
$this->info('');
foreach ($packages as $package) {
$this->info("Processing package: {$package->name}");

$composerName = $package->name;

$latestVersion = $package->latestVersion;
if (empty($latestVersion)) {
$this->error("No latest version found for package: {$package->name}");
continue;
}

$filesystem->makeDirectory($directory = storage_path('packages/'.$composerName), 0755, true, true);

if (!file_exists($directory.'/composer.json')) {
$cloneProcess = new Process([
'wget', $latestVersion->dist_url, '-O', $archive = storage_path('packages/'.$composerName.'/archive.zip'),
]);
$cloneProcess->run();

if (!$cloneProcess->isSuccessful()) {
$this->info($cloneProcess->getOutput());
$this->error($cloneProcess->getErrorOutput());
$this->error("Failed to download package archive for: {$package->name}");
continue;
}

$unzipProcess = new Process([
'unzip', '-o', storage_path('packages/'.$composerName.'/archive.zip'),
], $directory);
$unzipProcess->run();

if (!$unzipProcess->isSuccessful()) {
$this->info($unzipProcess->getOutput());
$this->error($unzipProcess->getErrorOutput());
$this->error("Failed to clone repository for package: {$package->name}");
continue;
}

$this->info("Cloned package: {$package->name} to {$directory}");
}
$allDirs = $filesystem->directories($directory);
if (count($allDirs) > 1) {
$this->error("Multiple directories found in package directory for: {$package->name}");
$this->error("Directories: " . implode(', ', $allDirs));
continue;
$this->info("[!] Processing package: {$package->name}");
$this->info("[!] {$package->versions->count()}");
foreach ($package->versions as $latestVersion) {
dispatch_sync(new RepackageVersionInZipJob($package, $latestVersion));
}
$originalDirectory = $directory;
$directory = Arr::first($allDirs);
if (file_exists($pluginPath = $directory.'/Plugin.php')) {
$this->info("Plugin.php found for package: {$package->name}");
$content = file_get_contents($pluginPath);
// We need to extract the plugin Namespace;
preg_match('/namespace\s+([^;]+);/', $content, $matches);

if (isset($matches[1])) {
$pluginNamespace = str_replace('\\', '.', $matches[1]);
$this->info("Plugin namespace for package {$package->name}: {$pluginNamespace}");
$package->needs_additional_processing = false;
$package->code = $pluginNamespace;
$package->save();
} else {
$this->error("Failed to extract plugin namespace for package: {$package->name}");
}
}

if (file_exists($composerPath = $directory.'/composer.json')) {
$filesystem->deleteDirectory($directory);
$filesystem->deleteDirectory($originalDirectory);
$filesystem->delete($archive);
}

// After processing, you might want to update the package
$package->needs_additional_processing = false;
$package->save();

$this->info("Processed package: {$package->name}");
}

} while ($packages->hasMorePages());
}
}
61 changes: 61 additions & 0 deletions app/Console/Commands/ImportPackageByComposerName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Console\Commands;

use App\Jobs\RepackageVersionInZipJob;
use App\Models\Package;
use App\Repositories\PackageRepository;
use App\Services\PackagistClient;
use App\Services\PackagistService;
use Illuminate\Console\Command;

class ImportPackageByComposerName extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'packages:import-package {composerName : The composer name of the package to import (e.g., vendor/package)}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
$package = Package::query()->with('versions')->firstWhere('name', $this->argument('composerName'));

if (empty($package)) {
$matches = (new PackagistService(new PackagistClient()))->search($this->argument('composerName', ''));

app(PackageRepository::class)->syncPackages($matches, true);
}

$package = Package::query()->with('versions')->firstWhere('name', $this->argument('composerName'));

if (empty($package)) {
$this->error("Package {$this->argument('composerName')} not found after sync.");
return;
}

if ($package->versions()->count() === 0) {
$this->error("Package {$package->name} has no versions.");
return;
}

foreach ($package->versions as $version) {
$this->info("Processing version {$version->version} of package {$package->name}");
// Dispatch job to process the version
dispatch_sync(new RepackageVersionInZipJob($package, $version));
}

// dispatch_sync(new )
}
}
18 changes: 0 additions & 18 deletions app/Console/Commands/ParseCapturedResponses.php

This file was deleted.

Loading