linter fixes
This commit is contained in:
parent
031c8a5594
commit
082967095e
|
@ -13,4 +13,3 @@ $cliPlatform->init('CLI');
|
||||||
|
|
||||||
$cli = $cliPlatform->getCli();
|
$cli = $cliPlatform->getCli();
|
||||||
$cli->run();
|
$cli->run();
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,10 @@ namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Platform;
|
use Utopia\Platform\Platform;
|
||||||
|
|
||||||
class CLIPlatform extends Platform {
|
class CLIPlatform extends Platform
|
||||||
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->addService('cliTasks', new Tasks());
|
$this->addService('cliTasks', new Tasks());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ use Utopia\Storage\Storage;
|
||||||
use Utopia\Domains\Domain;
|
use Utopia\Domains\Domain;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Doctor extends Action{
|
class Doctor extends Action
|
||||||
|
{
|
||||||
public const NAME = 'doctor';
|
public const NAME = 'doctor';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
@ -252,4 +253,4 @@ class Doctor extends Action{
|
||||||
Console::error('Failed to check for a newer version' . "\n");
|
Console::error('Failed to check for a newer version' . "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Appwrite\Auth\Auth;
|
use Appwrite\Auth\Auth;
|
||||||
|
@ -11,9 +12,10 @@ use Utopia\Config\Config;
|
||||||
use Utopia\Validator\Text;
|
use Utopia\Validator\Text;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Install extends Action{
|
class Install extends Action
|
||||||
|
{
|
||||||
public const NAME = 'install';
|
public const NAME = 'install';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -238,4 +240,4 @@ class Install extends Action{
|
||||||
Console::success($message);
|
Console::success($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Appwrite\Auth\Auth;
|
use Appwrite\Auth\Auth;
|
||||||
|
@ -14,15 +15,16 @@ use Utopia\Database\Document;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Maintenance extends Action {
|
class Maintenance extends Action
|
||||||
|
{
|
||||||
public const NAME = 'maintenance';
|
public const NAME = 'maintenance';
|
||||||
|
|
||||||
protected function getConsoleDB(): Database
|
protected function getConsoleDB(): Database
|
||||||
{
|
{
|
||||||
global $register;
|
global $register;
|
||||||
|
|
||||||
$attempts = 0;
|
$attempts = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
$attempts++;
|
$attempts++;
|
||||||
|
@ -30,11 +32,11 @@ class Maintenance extends Action {
|
||||||
$database = new Database(new MariaDB($register->get('db')), $cache);
|
$database = new Database(new MariaDB($register->get('db')), $cache);
|
||||||
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
||||||
$database->setNamespace('_console'); // Main DB
|
$database->setNamespace('_console'); // Main DB
|
||||||
|
|
||||||
if (!$database->exists($database->getDefaultDatabase(), 'certificates')) {
|
if (!$database->exists($database->getDefaultDatabase(), 'certificates')) {
|
||||||
throw new \Exception('Console project not ready');
|
throw new \Exception('Console project not ready');
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // leave loop if successful
|
break; // leave loop if successful
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
||||||
|
@ -44,10 +46,10 @@ class Maintenance extends Action {
|
||||||
sleep(DATABASE_RECONNECT_SLEEP);
|
sleep(DATABASE_RECONNECT_SLEEP);
|
||||||
}
|
}
|
||||||
} while ($attempts < DATABASE_RECONNECT_MAX_ATTEMPTS);
|
} while ($attempts < DATABASE_RECONNECT_MAX_ATTEMPTS);
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -156,4 +158,4 @@ class Maintenance extends Action {
|
||||||
renewCertificates($database);
|
renewCertificates($database);
|
||||||
}, $interval);
|
}, $interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
@ -13,10 +14,10 @@ use Utopia\Database\Validator\Authorization;
|
||||||
use Utopia\Validator\Text;
|
use Utopia\Validator\Text;
|
||||||
use Swoole\Event;
|
use Swoole\Event;
|
||||||
|
|
||||||
class Migrate extends Action{
|
class Migrate extends Action
|
||||||
|
{
|
||||||
public const NAME = 'migrate';
|
public const NAME = 'migrate';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -24,7 +25,8 @@ class Migrate extends Action{
|
||||||
->callback(fn ($version) => $this->action($version));
|
->callback(fn ($version) => $this->action($version));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action($version) {
|
public function action($version)
|
||||||
|
{
|
||||||
global $register;
|
global $register;
|
||||||
Authorization::disable();
|
Authorization::disable();
|
||||||
if (!array_key_exists($version, Migration::$versions)) {
|
if (!array_key_exists($version, Migration::$versions)) {
|
||||||
|
@ -92,4 +94,4 @@ class Migrate extends Action{
|
||||||
$redis->flushAll();
|
$redis->flushAll();
|
||||||
Console::success('Data Migration Completed');
|
Console::success('Data Migration Completed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
@ -24,10 +25,10 @@ use Appwrite\SDK\Language\SwiftClient;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class SDKs extends Action{
|
class SDKs extends Action
|
||||||
|
{
|
||||||
public const NAME = 'sdks';
|
public const NAME = 'sdks';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -268,4 +269,4 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
|
||||||
Console::exit();
|
Console::exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
@ -8,10 +9,10 @@ use Utopia\CLI\Console;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Validator\Hostname;
|
use Utopia\Validator\Hostname;
|
||||||
|
|
||||||
class SSL extends Action{
|
class SSL extends Action
|
||||||
|
{
|
||||||
public const NAME = 'ssl';
|
public const NAME = 'ssl';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -31,4 +32,4 @@ class SSL extends Action{
|
||||||
->setSkipRenewCheck(true)
|
->setSkipRenewCheck(true)
|
||||||
->trigger();
|
->trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
@ -15,10 +16,10 @@ use Utopia\Request;
|
||||||
use Utopia\Validator\WhiteList;
|
use Utopia\Validator\WhiteList;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class Specs extends Action{
|
class Specs extends Action
|
||||||
|
{
|
||||||
public const NAME = 'specs';
|
public const NAME = 'specs';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -266,4 +267,4 @@ class Specs extends Action{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\Platform\Service;
|
use Utopia\Platform\Service;
|
||||||
|
|
||||||
class Tasks extends Service {
|
class Tasks extends Service
|
||||||
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->type = self::TYPE_CLI;
|
$this->type = self::TYPE_CLI;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
@ -17,25 +18,26 @@ use Utopia\Registry\Registry;
|
||||||
use Utopia\Logger\Log;
|
use Utopia\Logger\Log;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Usage extends Action{
|
class Usage extends Action
|
||||||
|
{
|
||||||
public const NAME = 'usage';
|
public const NAME = 'usage';
|
||||||
|
|
||||||
protected function getDatabase(Registry &$register, string $namespace): Database
|
protected function getDatabase(Registry &$register, string $namespace): Database
|
||||||
{
|
{
|
||||||
$attempts = 0;
|
$attempts = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
$attempts++;
|
$attempts++;
|
||||||
|
|
||||||
$db = $register->get('db');
|
$db = $register->get('db');
|
||||||
$redis = $register->get('cache');
|
$redis = $register->get('cache');
|
||||||
|
|
||||||
$cache = new Cache(new RedisCache($redis));
|
$cache = new Cache(new RedisCache($redis));
|
||||||
$database = new Database(new MariaDB($db), $cache);
|
$database = new Database(new MariaDB($db), $cache);
|
||||||
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
||||||
$database->setNamespace($namespace);
|
$database->setNamespace($namespace);
|
||||||
|
|
||||||
if (!$database->exists($database->getDefaultDatabase(), 'projects')) {
|
if (!$database->exists($database->getDefaultDatabase(), 'projects')) {
|
||||||
throw new Exception('Projects collection not ready');
|
throw new Exception('Projects collection not ready');
|
||||||
}
|
}
|
||||||
|
@ -48,10 +50,10 @@ class Usage extends Action{
|
||||||
sleep(DATABASE_RECONNECT_SLEEP);
|
sleep(DATABASE_RECONNECT_SLEEP);
|
||||||
}
|
}
|
||||||
} while ($attempts < DATABASE_RECONNECT_MAX_ATTEMPTS);
|
} while ($attempts < DATABASE_RECONNECT_MAX_ATTEMPTS);
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getInfluxDB(Registry &$register): InfluxDatabase
|
protected function getInfluxDB(Registry &$register): InfluxDatabase
|
||||||
{
|
{
|
||||||
/** @var InfluxDB\Client $client */
|
/** @var InfluxDB\Client $client */
|
||||||
|
@ -59,7 +61,7 @@ class Usage extends Action{
|
||||||
$attempts = 0;
|
$attempts = 0;
|
||||||
$max = 10;
|
$max = 10;
|
||||||
$sleep = 1;
|
$sleep = 1;
|
||||||
|
|
||||||
do { // check if telegraf database is ready
|
do { // check if telegraf database is ready
|
||||||
try {
|
try {
|
||||||
$attempts++;
|
$attempts++;
|
||||||
|
@ -77,17 +79,18 @@ class Usage extends Action{
|
||||||
} while ($attempts < $max);
|
} while ($attempts < $max);
|
||||||
return $database;
|
return $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->desc('Schedules syncing data from influxdb to Appwrite console db')
|
->desc('Schedules syncing data from influxdb to Appwrite console db')
|
||||||
->callback(fn () => $this->action());
|
->callback(fn () => $this->action());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action() {
|
public function action()
|
||||||
|
{
|
||||||
|
|
||||||
global $register;
|
global $register;
|
||||||
|
|
||||||
|
@ -96,34 +99,34 @@ class Usage extends Action{
|
||||||
|
|
||||||
$logError = function (Throwable $error, string $action = 'syncUsageStats') use ($register) {
|
$logError = function (Throwable $error, string $action = 'syncUsageStats') use ($register) {
|
||||||
$logger = $register->get('logger');
|
$logger = $register->get('logger');
|
||||||
|
|
||||||
if ($logger) {
|
if ($logger) {
|
||||||
$version = App::getEnv('_APP_VERSION', 'UNKNOWN');
|
$version = App::getEnv('_APP_VERSION', 'UNKNOWN');
|
||||||
|
|
||||||
$log = new Log();
|
$log = new Log();
|
||||||
$log->setNamespace("usage");
|
$log->setNamespace("usage");
|
||||||
$log->setServer(\gethostname());
|
$log->setServer(\gethostname());
|
||||||
$log->setVersion($version);
|
$log->setVersion($version);
|
||||||
$log->setType(Log::TYPE_ERROR);
|
$log->setType(Log::TYPE_ERROR);
|
||||||
$log->setMessage($error->getMessage());
|
$log->setMessage($error->getMessage());
|
||||||
|
|
||||||
$log->addTag('code', $error->getCode());
|
$log->addTag('code', $error->getCode());
|
||||||
$log->addTag('verboseType', get_class($error));
|
$log->addTag('verboseType', get_class($error));
|
||||||
|
|
||||||
$log->addExtra('file', $error->getFile());
|
$log->addExtra('file', $error->getFile());
|
||||||
$log->addExtra('line', $error->getLine());
|
$log->addExtra('line', $error->getLine());
|
||||||
$log->addExtra('trace', $error->getTraceAsString());
|
$log->addExtra('trace', $error->getTraceAsString());
|
||||||
$log->addExtra('detailedTrace', $error->getTrace());
|
$log->addExtra('detailedTrace', $error->getTrace());
|
||||||
|
|
||||||
$log->setAction($action);
|
$log->setAction($action);
|
||||||
|
|
||||||
$isProduction = App::getEnv('_APP_ENV', 'development') === 'production';
|
$isProduction = App::getEnv('_APP_ENV', 'development') === 'production';
|
||||||
$log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING);
|
$log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING);
|
||||||
|
|
||||||
$responseCode = $logger->addLog($log);
|
$responseCode = $logger->addLog($log);
|
||||||
Console::info('Usage stats log pushed with status code: ' . $responseCode);
|
Console::info('Usage stats log pushed with status code: ' . $responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::warning("Failed: {$error->getMessage()}");
|
Console::warning("Failed: {$error->getMessage()}");
|
||||||
Console::warning($error->getTraceAsString());
|
Console::warning($error->getTraceAsString());
|
||||||
};
|
};
|
||||||
|
@ -176,4 +179,4 @@ class Usage extends Action{
|
||||||
Console::info("[{$now}] Aggregation took {$loopTook} seconds");
|
Console::info("[{$now}] Aggregation took {$loopTook} seconds");
|
||||||
}, $interval);
|
}, $interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Vars extends Action{
|
class Vars extends Action
|
||||||
|
{
|
||||||
public const NAME = 'vars';
|
public const NAME = 'vars';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -31,4 +33,4 @@ class Vars extends Action{
|
||||||
Console::log('- ' . $value['name'] . '=' . App::getEnv($value['name'], ''));
|
Console::log('- ' . $value['name'] . '=' . App::getEnv($value['name'], ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Appwrite\Task;
|
namespace Appwrite\Task;
|
||||||
|
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
|
|
||||||
class Version extends Action {
|
class Version extends Action
|
||||||
|
{
|
||||||
public const NAME = 'version';
|
public const NAME = 'version';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
Loading…
Reference in a new issue