forked from GNUsocial/gnu-social
[OfflineBackup] Fix plugin
This commit is contained in:
parent
566214ac62
commit
25ee5ed1f9
@ -46,15 +46,18 @@ if (!defined('STATUSNET')) {
|
|||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OfflineBackupPlugin extends Plugin
|
class OfflineBackupPlugin extends Plugin
|
||||||
{
|
{
|
||||||
const PLUGIN_VERSION = '2.0.0';
|
const PLUGIN_VERSION = '2.0.0';
|
||||||
|
|
||||||
function onRouterInitialized($m)
|
public function onRouterInitialized($m)
|
||||||
{
|
{
|
||||||
$m->connect('main/backupaccount',
|
$m->connect(
|
||||||
['action' => 'offlinebackup']);
|
'main/backupaccount',
|
||||||
|
['action' => 'offlinebackup'],
|
||||||
|
[],
|
||||||
|
true // Overwrite native backup tool
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +66,9 @@ class OfflineBackupPlugin extends Plugin
|
|||||||
*
|
*
|
||||||
* @param QueueManager $qm current queue manager
|
* @param QueueManager $qm current queue manager
|
||||||
*
|
*
|
||||||
* @return boolean hook value
|
* @return bool hook value
|
||||||
*/
|
*/
|
||||||
|
public function onEndInitializeQueueManager($qm)
|
||||||
function onEndInitializeQueueManager($qm)
|
|
||||||
{
|
{
|
||||||
$qm->connect('backoff', 'OfflineBackupQueueHandler');
|
$qm->connect('backoff', 'OfflineBackupQueueHandler');
|
||||||
return true;
|
return true;
|
||||||
@ -74,13 +76,15 @@ class OfflineBackupPlugin extends Plugin
|
|||||||
|
|
||||||
public function onPluginVersion(array &$versions): bool
|
public function onPluginVersion(array &$versions): bool
|
||||||
{
|
{
|
||||||
$versions[] = array('name' => 'OfflineBackup',
|
$versions[] = [
|
||||||
|
'name' => 'OfflineBackup',
|
||||||
'version' => self::PLUGIN_VERSION,
|
'version' => self::PLUGIN_VERSION,
|
||||||
'author' => 'Evan Prodromou',
|
'author' => 'Evan Prodromou',
|
||||||
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/OfflineBackup',
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/OfflineBackup',
|
||||||
'rawdescription' =>
|
'rawdescription' =>
|
||||||
// TRANS: Plugin description.
|
// TRANS: Module description.
|
||||||
_m('Backup user data in offline queue and email when ready.'));
|
_m('Backup user data in offline queue and email when ready.')
|
||||||
|
];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,28 +44,26 @@ if (!defined('STATUSNET')) {
|
|||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OfflinebackupAction extends BackupaccountAction
|
class OfflinebackupAction extends BackupaccountAction
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handler method
|
* Handler method
|
||||||
*
|
*
|
||||||
* @param array $argarray is ignored since it's now passed in in prepare()
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws ClientException
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
|
public function handle(): void
|
||||||
function handle($argarray=null)
|
|
||||||
{
|
{
|
||||||
if ($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
$this->queueBackup();
|
$this->queueBackup();
|
||||||
} else {
|
} else {
|
||||||
$this->showPage();
|
$this->showPage();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function queueBackup()
|
public function queueBackup(): void
|
||||||
{
|
{
|
||||||
$cur = common_current_user();
|
$cur = common_current_user();
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ class OfflinebackupAction extends BackupaccountAction
|
|||||||
$this->showPage();
|
$this->showPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showContent()
|
public function showContent(): void
|
||||||
{
|
{
|
||||||
if ($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
$this->text(_('Backup queued. You will get a notification by email when your backup is ready to download.'));
|
$this->text(_('Backup queued. You will get a notification by email when your backup is ready to download.'));
|
||||||
|
@ -44,15 +44,14 @@ if (!defined('STATUSNET')) {
|
|||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OfflineBackupQueueHandler extends QueueHandler
|
class OfflineBackupQueueHandler extends QueueHandler
|
||||||
{
|
{
|
||||||
function transport()
|
public function transport()
|
||||||
{
|
{
|
||||||
return 'backoff';
|
return 'backoff';
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle($object) : bool
|
public function handle($object): bool
|
||||||
{
|
{
|
||||||
$userId = $object;
|
$userId = $object;
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeBackupFile($user)
|
public function makeBackupFile($user)
|
||||||
{
|
{
|
||||||
// XXX: this is pretty lose-y; try another way
|
// XXX: this is pretty lose-y; try another way
|
||||||
|
|
||||||
@ -95,23 +94,27 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
return $fileName;
|
return $fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function notifyBackupFile($user, $fileName)
|
public function notifyBackupFile($user, $fileName)
|
||||||
{
|
{
|
||||||
$fileUrl = File::url($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".
|
"%s\n".
|
||||||
"Thanks for your time,\n",
|
"Thanks for your time,\n",
|
||||||
"%s\n"),
|
"%s\n"
|
||||||
|
),
|
||||||
$fileUrl,
|
$fileUrl,
|
||||||
common_config('site', 'name'));
|
common_config('site', 'name')
|
||||||
|
);
|
||||||
|
|
||||||
$headers = _mail_prepare_headers('offlinebackup', $user->nickname, $user->nickname);
|
$headers = _mail_prepare_headers('offlinebackup', $user->nickname, $user->nickname);
|
||||||
|
|
||||||
mail_to_user($user, _('Backup file ready for download'), $body, $headers);
|
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);
|
common_log(LOG_INFO, 'dumping notices by ' . $user->nickname . ' to directory ' . $dir);
|
||||||
|
|
||||||
@ -122,7 +125,6 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
$notice = $stream->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
|
$notice = $stream->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
|
||||||
|
|
||||||
while ($notice->fetch()) {
|
while ($notice->fetch()) {
|
||||||
@ -139,11 +141,10 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page++;
|
$page++;
|
||||||
|
|
||||||
} while ($notice->N > NOTICES_PER_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);
|
common_log(LOG_INFO, 'dumping faves by ' . $user->nickname . ' to directory ' . $dir);
|
||||||
|
|
||||||
@ -167,11 +168,10 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page++;
|
$page++;
|
||||||
|
|
||||||
} while ($fave->N > NOTICES_PER_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);
|
common_log(LOG_INFO, 'dumping subscriptions by ' . $user->nickname . ' to directory ' . $dir);
|
||||||
|
|
||||||
@ -198,11 +198,10 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page++;
|
$page++;
|
||||||
|
|
||||||
} while ($sub->N > PROFILES_PER_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);
|
common_log(LOG_INFO, 'dumping subscribers to ' . $user->nickname . ' to directory ' . $dir);
|
||||||
|
|
||||||
@ -229,18 +228,16 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page++;
|
$page++;
|
||||||
|
|
||||||
} while ($sub->N > PROFILES_PER_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);
|
common_log(LOG_INFO, 'dumping memberships of ' . $user->nickname . ' to directory ' . $dir);
|
||||||
|
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
$mem = Group_member::byMember($user->id, ($page-1)*GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1);
|
$mem = Group_member::byMember($user->id, ($page-1)*GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1);
|
||||||
|
|
||||||
while ($mem->fetch()) {
|
while ($mem->fetch()) {
|
||||||
@ -258,11 +255,10 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page++;
|
$page++;
|
||||||
|
|
||||||
} while ($mem->N > GROUPS_PER_PAGE);
|
} while ($mem->N > GROUPS_PER_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeActivityFeed($user, $tmpdir, $fullPath)
|
public function makeActivityFeed($user, $tmpdir, $fullPath)
|
||||||
{
|
{
|
||||||
$handle = fopen($fullPath, 'c');
|
$handle = fopen($fullPath, 'c');
|
||||||
|
|
||||||
@ -285,7 +281,7 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
fclose($handle);
|
fclose($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeFeedHeader($user, $handle)
|
public function writeFeedHeader($user, $handle)
|
||||||
{
|
{
|
||||||
fwrite($handle, '<?xml version="1.0" encoding="UTF-8"?>');
|
fwrite($handle, '<?xml version="1.0" encoding="UTF-8"?>');
|
||||||
fwrite($handle, "\n");
|
fwrite($handle, "\n");
|
||||||
@ -302,12 +298,12 @@ class OfflineBackupQueueHandler extends QueueHandler
|
|||||||
fwrite($handle, "\n");
|
fwrite($handle, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeFeedFooter($user, $handle)
|
public function writeFeedFooter($user, $handle)
|
||||||
{
|
{
|
||||||
fwrite($handle, '</feed>');
|
fwrite($handle, '</feed>');
|
||||||
}
|
}
|
||||||
|
|
||||||
function delTree($dir)
|
public function delTree($dir)
|
||||||
{
|
{
|
||||||
if (is_dir($dir)) {
|
if (is_dir($dir)) {
|
||||||
$objects = scandir($dir);
|
$objects = scandir($dir);
|
||||||
|
Loading…
Reference in New Issue
Block a user