Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file transfer stuck on pending #29

Merged
merged 7 commits into from
May 15, 2024
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
Loading