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
80 changes: 80 additions & 0 deletions bin/MigrationCLI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

require_once __DIR__.'/.././vendor/autoload.php';

use Dotenv\Dotenv;
use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite;
use Utopia\Migration\Sources\Appwrite;
use Utopia\Migration\Transfer;

/**
* Migrations CLI Tool
*/
class MigrationCLI
{
protected Transfer $transfer;

/**
* Prints the current status of migrations as a table after wiping the screen
*/
public function drawFrame()
{
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';

$statusCounters = $this->transfer->getStatusCounters();

$mask = "| %15.15s | %-7.7s | %10.10s | %7.7s | %7.7s | %8.8s |\n";
printf($mask, 'Resource', 'Pending', 'Processing', 'Skipped', 'Warning', 'Success');
printf($mask, '-------------', '-------------', '-------------', '-------------', '-------------', '-------------');
foreach ($statusCounters as $resource => $data) {
printf($mask, $resource, $data['pending'], $data['processing'], $data['skip'], $data['warning'], $data['success']);
}
}

public function start()
{
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

/**
* Initialise All Source Adapters
*/
$source = new Appwrite(
$_ENV['SOURCE_APPWRITE_TEST_PROJECT'],
$_ENV['SOURCE_APPWRITE_TEST_ENDPOINT'],
$_ENV['SOURCE_APPWRITE_TEST_KEY']
);

// $source->report();

$destination = new DestinationsAppwrite(
$_ENV['DESTINATION_APPWRITE_TEST_PROJECT'],
$_ENV['DESTINATION_APPWRITE_TEST_ENDPOINT'],
$_ENV['DESTINATION_APPWRITE_TEST_KEY']
);

/**
* Initialise Transfer Class
*/
$this->transfer = new Transfer(
$source,
$destination
);

/**
* Run Transfer
*/
$this->transfer->run(
$source->getSupportedResources(),
function (array $resources) {
$this->drawFrame();
}
);

var_dump('Complete');
}
}

$instance = new MigrationCLI();
$instance->start();
$instance->drawFrame();
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"require": {
"php": "8.*",
"utopia-php/cli": "0.*",
"appwrite/appwrite": "10.1.0"
},
"require-dev": {
Expand Down
4 changes: 4 additions & 0 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,13 @@ public function importFile(File $file): File
if ($response['signature'] !== $file->getSignature()) {
$file->setStatus(Resource::STATUS_WARNING, 'File signature mismatch, Possibly corrupted.');
}
} else {
$file->setStatus(Resource::STATUS_SUCCESS);
}
}

$file->setData('');

return $file;
}

Expand Down