[OfflineBackup] Fix plugin

This commit is contained in:
Diogo Cordeiro 2019-08-10 22:35:45 +01:00
parent 566214ac62
commit 25ee5ed1f9
3 changed files with 57 additions and 59 deletions

View File

@ -46,15 +46,18 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class OfflineBackupPlugin extends Plugin
{
const PLUGIN_VERSION = '2.0.0';
function onRouterInitialized($m)
public function onRouterInitialized($m)
{
$m->connect('main/backupaccount',
['action' => 'offlinebackup']);
$m->connect(
'main/backupaccount',
['action' => 'offlinebackup'],
[],
true // Overwrite native backup tool
);
return true;
}
@ -63,10 +66,9 @@ class OfflineBackupPlugin extends Plugin
*
* @param QueueManager $qm current queue manager
*
* @return boolean hook value
* @return bool hook value
*/
function onEndInitializeQueueManager($qm)
public function onEndInitializeQueueManager($qm)
{
$qm->connect('backoff', 'OfflineBackupQueueHandler');
return true;
@ -74,13 +76,15 @@ class OfflineBackupPlugin extends Plugin
public function onPluginVersion(array &$versions): bool
{
$versions[] = array('name' => 'OfflineBackup',
$versions[] = [
'name' => 'OfflineBackup',
'version' => self::PLUGIN_VERSION,
'author' => 'Evan Prodromou',
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/OfflineBackup',
'rawdescription' =>
// TRANS: Plugin description.
_m('Backup user data in offline queue and email when ready.'));
// TRANS: Module description.
_m('Backup user data in offline queue and email when ready.')
];
return true;
}
}

View File

@ -44,28 +44,26 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class OfflinebackupAction extends BackupaccountAction
{
/**
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void
* @throws ClientException
* @throws ReflectionException
* @throws ServerException
*/
function handle($argarray=null)
public function handle(): void
{
if ($this->isPost()) {
$this->queueBackup();
} else {
$this->showPage();
}
return;
}
function queueBackup()
public function queueBackup(): void
{
$cur = common_current_user();
@ -76,7 +74,7 @@ class OfflinebackupAction extends BackupaccountAction
$this->showPage();
}
function showContent()
public function showContent(): void
{
if ($this->isPost()) {
$this->text(_('Backup queued. You will get a notification by email when your backup is ready to download.'));

View File

@ -44,15 +44,14 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class OfflineBackupQueueHandler extends QueueHandler
{
function transport()
public function transport()
{
return 'backoff';
}
function handle($object) : bool
public function handle($object): bool
{
$userId = $object;
@ -69,7 +68,7 @@ class OfflineBackupQueueHandler extends QueueHandler
return true;
}
function makeBackupFile($user)
public function makeBackupFile($user)
{
// XXX: this is pretty lose-y; try another way
@ -95,23 +94,27 @@ class OfflineBackupQueueHandler extends QueueHandler
return $fileName;
}
function notifyBackupFile($user, $fileName)
public function notifyBackupFile($user, $fileName)
{
$fileUrl = File::url($fileName);
$body = sprintf(_m("The backup file you requested is ready for download.\n\n".
$body = sprintf(
_m(
"The backup file you requested is ready for download.\n\n".
"%s\n".
"Thanks for your time,\n",
"%s\n"),
"%s\n"
),
$fileUrl,
common_config('site', 'name'));
common_config('site', 'name')
);
$headers = _mail_prepare_headers('offlinebackup', $user->nickname, $user->nickname);
mail_to_user($user, _('Backup file ready for download'), $body, $headers);
}
function dumpNotices($user, $dir)
public function dumpNotices($user, $dir)
{
common_log(LOG_INFO, 'dumping notices by ' . $user->nickname . ' to directory ' . $dir);
@ -122,7 +125,6 @@ class OfflineBackupQueueHandler extends QueueHandler
$page = 1;
do {
$notice = $stream->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
while ($notice->fetch()) {
@ -139,11 +141,10 @@ class OfflineBackupQueueHandler extends QueueHandler
}
$page++;
} while ($notice->N > NOTICES_PER_PAGE);
}
function dumpFaves($user, $dir)
public function dumpFaves($user, $dir)
{
common_log(LOG_INFO, 'dumping faves by ' . $user->nickname . ' to directory ' . $dir);
@ -167,11 +168,10 @@ class OfflineBackupQueueHandler extends QueueHandler
}
$page++;
} while ($fave->N > NOTICES_PER_PAGE);
}
function dumpSubscriptions($user, $dir)
public function dumpSubscriptions($user, $dir)
{
common_log(LOG_INFO, 'dumping subscriptions by ' . $user->nickname . ' to directory ' . $dir);
@ -198,11 +198,10 @@ class OfflineBackupQueueHandler extends QueueHandler
}
$page++;
} while ($sub->N > PROFILES_PER_PAGE);
}
function dumpSubscribers($user, $dir)
public function dumpSubscribers($user, $dir)
{
common_log(LOG_INFO, 'dumping subscribers to ' . $user->nickname . ' to directory ' . $dir);
@ -229,18 +228,16 @@ class OfflineBackupQueueHandler extends QueueHandler
}
$page++;
} while ($sub->N > PROFILES_PER_PAGE);
}
function dumpGroups($user, $dir)
public function dumpGroups($user, $dir)
{
common_log(LOG_INFO, 'dumping memberships of ' . $user->nickname . ' to directory ' . $dir);
$page = 1;
do {
$mem = Group_member::byMember($user->id, ($page-1)*GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1);
while ($mem->fetch()) {
@ -258,11 +255,10 @@ class OfflineBackupQueueHandler extends QueueHandler
}
$page++;
} while ($mem->N > GROUPS_PER_PAGE);
}
function makeActivityFeed($user, $tmpdir, $fullPath)
public function makeActivityFeed($user, $tmpdir, $fullPath)
{
$handle = fopen($fullPath, 'c');
@ -285,7 +281,7 @@ class OfflineBackupQueueHandler extends QueueHandler
fclose($handle);
}
function writeFeedHeader($user, $handle)
public function writeFeedHeader($user, $handle)
{
fwrite($handle, '<?xml version="1.0" encoding="UTF-8"?>');
fwrite($handle, "\n");
@ -302,12 +298,12 @@ class OfflineBackupQueueHandler extends QueueHandler
fwrite($handle, "\n");
}
function writeFeedFooter($user, $handle)
public function writeFeedFooter($user, $handle)
{
fwrite($handle, '</feed>');
}
function delTree($dir)
public function delTree($dir)
{
if (is_dir($dir)) {
$objects = scandir($dir);