2019-12-31 23:55:39 +13:00
|
|
|
#!/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once __DIR__.'/../init.php';
|
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
global $register, $projectDB, $console;
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
use Database\Database;
|
|
|
|
use Database\Validator\Authorization;
|
2019-12-31 23:55:39 +13:00
|
|
|
use Utopia\CLI\CLI;
|
|
|
|
use Utopia\CLI\Console;
|
|
|
|
|
|
|
|
$cli = new CLI();
|
|
|
|
$db = $register->get('db');
|
|
|
|
|
|
|
|
$callbacks = [
|
2020-02-11 05:16:02 +13:00
|
|
|
'0.4.0' => function() {
|
2019-12-31 23:55:39 +13:00
|
|
|
Console::log('I got nothing to do.');
|
|
|
|
},
|
2020-02-11 05:16:02 +13:00
|
|
|
'0.5.0' => function($project) use ($db, $projectDB) {
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
Console::info('Altering table for project: '.$project->getUid());
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
try {
|
|
|
|
$statement = $db->prepare("
|
|
|
|
ALTER TABLE `appwrite`.`app_{$project->getUid()}.audit.audit` DROP COLUMN IF EXISTS `userType`;
|
|
|
|
ALTER TABLE `appwrite`.`app_{$project->getUid()}.audit.audit` DROP INDEX IF EXISTS `index_1`;
|
|
|
|
ALTER TABLE `appwrite`.`app_{$project->getUid()}.audit.audit` ADD INDEX IF NOT EXISTS `index_1` (`userId` ASC);
|
|
|
|
");
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
$statement->execute();
|
|
|
|
}
|
|
|
|
catch (\Exception $e) {
|
|
|
|
Console::error($e->getMessage().'/');
|
|
|
|
}
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
$statement->closeCursor();
|
|
|
|
|
|
|
|
$limit = 30;
|
|
|
|
$sum = 30;
|
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
while ($sum >= 30) {
|
|
|
|
$users = $projectDB->getCollection([
|
|
|
|
'limit' => $limit,
|
|
|
|
'offset' => $offset,
|
|
|
|
'orderField' => 'name',
|
|
|
|
'orderType' => 'ASC',
|
|
|
|
'orderCast' => 'string',
|
|
|
|
'filters' => [
|
|
|
|
'$collection='.Database::SYSTEM_COLLECTION_USERS,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$sum = count($users);
|
2019-12-31 23:55:39 +13:00
|
|
|
|
2020-02-11 05:16:02 +13:00
|
|
|
Console::success('Fetched '.$sum.' users...');
|
|
|
|
|
|
|
|
foreach($users as $user) {
|
|
|
|
$user
|
|
|
|
->setAttribute('emailVerification', $user->getAttribute('confirm', false))
|
|
|
|
->removeAttribute('confirm')
|
|
|
|
;
|
|
|
|
|
|
|
|
if(!$projectDB->updateDocument($user->getArrayCopy())) {
|
|
|
|
Console::error('Failed to update user');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Console::success('Updated user succefully');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$offset = $offset + $limit;
|
2019-12-31 23:55:39 +13:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
$cli
|
|
|
|
->task('run')
|
2020-02-11 05:16:02 +13:00
|
|
|
->action(function () use ($console, $db, $projectDB, $consoleDB, $callbacks) {
|
2019-12-31 23:55:39 +13:00
|
|
|
Console::success('Starting Upgrade');
|
2020-02-11 05:16:02 +13:00
|
|
|
|
|
|
|
Authorization::disable();
|
|
|
|
|
|
|
|
$limit = 30;
|
|
|
|
$sum = 30;
|
|
|
|
$offset = 0;
|
|
|
|
$projects = [$console];
|
|
|
|
|
|
|
|
while ($sum >= 30) {
|
|
|
|
foreach($projects as $project) {
|
|
|
|
$projectDB->setNamespace('app_'.$project->getUid());
|
|
|
|
|
|
|
|
$callbacks['0.5.0']($project);
|
|
|
|
}
|
|
|
|
|
|
|
|
$projects = $consoleDB->getCollection([
|
|
|
|
'limit' => $limit,
|
|
|
|
'offset' => $offset,
|
|
|
|
'orderField' => 'name',
|
|
|
|
'orderType' => 'ASC',
|
|
|
|
'orderCast' => 'string',
|
|
|
|
'filters' => [
|
|
|
|
'$collection='.Database::SYSTEM_COLLECTION_PROJECTS,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$sum = count($projects);
|
|
|
|
$offset = $offset + $limit;
|
|
|
|
|
|
|
|
Console::success('Fetched '.$sum.' projects...');
|
|
|
|
}
|
2019-12-31 23:55:39 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
$cli->run();
|