Reformat code

- Reformat Console\Storage
- Reformat Core\StorageManager
- Simplify logic in Worker\CronJobs
This commit is contained in:
Hypolite Petovan 2019-03-17 19:04:42 -04:00
parent 3a0a6cd659
commit f225a6c51a
3 changed files with 44 additions and 56 deletions

View file

@ -49,15 +49,15 @@ HELP;
return -1; return -1;
} }
switch($this->args[0]) { switch ($this->args[0]) {
case 'list': case 'list':
return $this->do_list(); return $this->doList();
break; break;
case 'set': case 'set':
return $this->do_set(); return $this->doSet();
break; break;
case 'move': case 'move':
return $this->do_move(); return $this->doMove();
break; break;
} }
@ -65,20 +65,20 @@ HELP;
return -1; return -1;
} }
protected function do_list() protected function doList()
{ {
$rowfmt = ' %-3s | %-20s'; $rowfmt = ' %-3s | %-20s';
$current = StorageManager::getBackend(); $current = StorageManager::getBackend();
$this->out(sprintf($rowfmt, 'Sel', 'Name')); $this->out(sprintf($rowfmt, 'Sel', 'Name'));
$this->out('-----------------------'); $this->out('-----------------------');
$isregisterd = false; $isregisterd = false;
foreach(StorageManager::listBackends() as $name => $class) { foreach (StorageManager::listBackends() as $name => $class) {
$issel = ' '; $issel = ' ';
if ($current === $class) { if ($current === $class) {
$issel = '*'; $issel = '*';
$isregisterd = true; $isregisterd = true;
}; };
$this->out(sprintf($rowfmt, $issel , $name )); $this->out(sprintf($rowfmt, $issel, $name));
} }
if ($current === '') { if ($current === '') {
@ -92,7 +92,7 @@ HELP;
return 0; return 0;
} }
protected function do_set() protected function doSet()
{ {
if (count($this->args) !== 2) { if (count($this->args) !== 2) {
throw new CommandArgsException('Invalid arguments'); throw new CommandArgsException('Invalid arguments');
@ -110,7 +110,7 @@ HELP;
return 0; return 0;
} }
protected function do_move() protected function doMove()
{ {
$tables = null; $tables = null;
if (count($this->args) < 1 || count($this->args) > 2) { if (count($this->args) < 1 || count($this->args) > 2) {

View file

@ -23,7 +23,7 @@ class StorageManager
private static function setup() private static function setup()
{ {
if (count(self::$backends)==0) { if (count(self::$backends) == 0) {
self::$backends = Config::get('storage', 'backends', self::$default_backends); self::$backends = Config::get('storage', 'backends', self::$default_backends);
} }
} }

View file

@ -35,54 +35,42 @@ class CronJobs
Logger::log("Starting cronjob " . $command, Logger::DEBUG); Logger::log("Starting cronjob " . $command, Logger::DEBUG);
// Call possible post update functions switch($command) {
// see src/Database/PostUpdate.php for more details case 'post_update':
if ($command == 'post_update') {
PostUpdate::update(); PostUpdate::update();
return; break;
}
// update nodeinfo data case 'nodeinfo':
if ($command == 'nodeinfo') {
nodeinfo_cron(); nodeinfo_cron();
return; break;
}
// Expire and remove user entries case 'expire_and_remove_users':
if ($command == 'expire_and_remove_users') {
self::expireAndRemoveUsers(); self::expireAndRemoveUsers();
return; break;
}
if ($command == 'update_contact_birthdays') { case 'update_contact_birthdays':
Contact::updateBirthdays(); Contact::updateBirthdays();
return; break;
}
if ($command == 'update_photo_albums') { case 'update_photo_albums':
self::updatePhotoAlbums(); self::updatePhotoAlbums();
return; break;
}
// Clear cache entries case 'clear_cache':
if ($command == 'clear_cache') {
self::clearCache($a); self::clearCache($a);
return; break;
}
// Repair missing Diaspora values in contacts case 'repair_diaspora':
if ($command == 'repair_diaspora') {
self::repairDiaspora($a); self::repairDiaspora($a);
return; break;
}
// Repair entries in the database case 'repair_database':
if ($command == 'repair_database') {
self::repairDatabase(); self::repairDatabase();
return; break;
}
default:
Logger::log("Xronjob " . $command . " is unknown.", Logger::DEBUG); Logger::log("Xronjob " . $command . " is unknown.", Logger::DEBUG);
}
return; return;
} }