mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Tests for clean up S3 orphans
This commit is contained in:
parent
a42223a0be
commit
2b6f0870b3
@ -43,23 +43,20 @@ class S3Cleanup extends Command
|
|||||||
$c1 = Company::on('db-ninja-01')->pluck('company_key');
|
$c1 = Company::on('db-ninja-01')->pluck('company_key');
|
||||||
$c2 = Company::on('db-ninja-02')->pluck('company_key');
|
$c2 = Company::on('db-ninja-02')->pluck('company_key');
|
||||||
|
|
||||||
$merged = $c1->merge($c2);
|
$merged = $c1->merge($c2)->toArray();
|
||||||
|
|
||||||
$c3 = Storage::disk(config('filesystems.default'))->directories();
|
$directories = Storage::disk(config('filesystems.default'))->directories();
|
||||||
|
|
||||||
$diff = $merged->diff($c3);
|
|
||||||
|
|
||||||
$this->LogMessage("Disk Cleanup");
|
$this->LogMessage("Disk Cleanup");
|
||||||
|
|
||||||
$this->logMessage("Folders to delete = ". $c1->count());
|
foreach($directories as $dir)
|
||||||
|
{
|
||||||
$diff->each(function ($dir){
|
if(!in_array($dir, $merged))
|
||||||
|
{
|
||||||
$this->logMessage("Deleting $dir");
|
$this->logMessage("Deleting $dir");
|
||||||
|
Storage::disk(config('filesystems.default'))->deleteDirectory($dir);
|
||||||
Storage::deleteDirectory($dir);
|
}
|
||||||
|
}
|
||||||
});
|
|
||||||
|
|
||||||
$this->logMessage("exiting");
|
$this->logMessage("exiting");
|
||||||
|
|
||||||
|
39
tests/Unit/S3CleanupTest.php
Normal file
39
tests/Unit/S3CleanupTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class S3CleanupTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMergeCollections()
|
||||||
|
{
|
||||||
|
$c1 = collect(["1","2","3","4"]);
|
||||||
|
$c2 = collect(["5","6","7","8"]);
|
||||||
|
|
||||||
|
$c3 = collect(["1","2","10"]);
|
||||||
|
|
||||||
|
$merged = $c1->merge($c2)->toArray();
|
||||||
|
|
||||||
|
$this->assertTrue(in_array("1", $merged));
|
||||||
|
$this->assertFalse(in_array("10", $merged));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user