Add mechanism at (un)install of an extension

Test if the install or uninstall has been successfully performed.
If these methods return true, all is ok but if a string is returned,
the string must explain the problem. This problem is stored in log file.

A feedback is given to explain to check log file.

This commit fix a problem in the english translation of
feedback.sub.feed.internal_problem.
This commit is contained in:
Marien Fressinaud
2015-01-14 21:38:35 +01:00
parent f1ffdd8b9d
commit 806b4de54f
4 changed files with 55 additions and 21 deletions

View File

@@ -88,15 +88,21 @@ class FreshRSS_extension_Controller extends Minz_ActionController {
$url_redirect);
}
$ext->install();
$res = $ext->install();
$ext_list = $conf->extensions_enabled;
array_push_unique($ext_list, $ext_name);
$conf->extensions_enabled = $ext_list;
$conf->save();
if ($res === true) {
$ext_list = $conf->extensions_enabled;
array_push_unique($ext_list, $ext_name);
$conf->extensions_enabled = $ext_list;
$conf->save();
Minz_Request::good(_t('feedback.extensions.enabled', $ext_name),
$url_redirect);
Minz_Request::good(_t('feedback.extensions.enable.ok', $ext_name),
$url_redirect);
} else {
Minz_Log::warning('Can not enable extension ' . $ext_name . ': ' . $res);
Minz_Request::bad(_t('feedback.extensions.enable.ko', $ext_name, _url('index', 'logs')),
$url_redirect);
}
}
Minz_Request::forward($url_redirect, true);
@@ -138,15 +144,21 @@ class FreshRSS_extension_Controller extends Minz_ActionController {
$url_redirect);
}
$ext->uninstall();
$res = $ext->uninstall();
$ext_list = $conf->extensions_enabled;
array_remove($ext_list, $ext_name);
$conf->extensions_enabled = $ext_list;
$conf->save();
if ($res === true) {
$ext_list = $conf->extensions_enabled;
array_remove($ext_list, $ext_name);
$conf->extensions_enabled = $ext_list;
$conf->save();
Minz_Request::good(_t('feedback.extensions.disabled', $ext_name),
$url_redirect);
Minz_Request::good(_t('feedback.extensions.disable.ok', $ext_name),
$url_redirect);
} else {
Minz_Log::warning('Can not unable extension ' . $ext_name . ': ' . $res);
Minz_Request::bad(_t('feedback.extensions.disable.ko', $ext_name, _url('index', 'logs')),
$url_redirect);
}
}
Minz_Request::forward($url_redirect, true);

View File

@@ -31,8 +31,14 @@ return array(
),
'extensions' => array(
'already_enabled' => '%s is already enabled',
'disabled' => '%s is now disabled',
'enabled' => '%s is now enabled',
'disable' => array(
'ko' => '%s cannot be disabled. <a href="%s">Check FressRSS logs</a> for details.',
'ok' => '%s is now disabled',
),
'enable' => array(
'ko' => '%s cannot be enabled. <a href="%s">Check FressRSS logs</a> for details.',
'ok' => '%s is now enabled',
),
'no_access' => 'You have no access on %s',
'not_enabled' => '%s is not enabled yet',
'not_found' => '%s does not exist',
@@ -67,7 +73,7 @@ return array(
'already_subscribed' => 'You have already subscribed to <em>%s</em>',
'deleted' => 'Feed has been deleted',
'error' => 'Feed cannot be updated',
'internal_problem_feed' => 'The RSS feed could not be added. <a href="%s">Check FressRSS logs</a> for details.',
'internal_problem' => 'The RSS feed could not be added. <a href="%s">Check FressRSS logs</a> for details.',
'invalid_url' => 'URL <em>%s</em> is invalid',
'marked_read' => 'Feeds have been marked as read',
'n_actualized' => '%d feeds have been updated',

View File

@@ -31,8 +31,14 @@ return array(
),
'extensions' => array(
'already_enabled' => '%s est déjà activée',
'disabled' => '%s est désormais désactivée',
'enabled' => '%s est désormais activée',
'disable' => array(
'ko' => '%s ne peut pas être désactivée. <a href="%s">Consulter les logs de FreshRSS</a> pour plus de détails.',
'ok' => '%s est désormais désactivée',
),
'enable' => array(
'ko' => '%s ne peut pas être activée. <a href="%s">Consulter les logs de FreshRSS</a> pour plus de détails.',
'ok' => '%s est désormais activée',
),
'no_access' => 'Vous navez aucun accès sur %s',
'not_enabled' => '%s nest pas encore activée',
'not_found' => '%s nexiste pas',

View File

@@ -51,16 +51,26 @@ class Minz_Extension {
* Used when installing an extension (e.g. update the database scheme).
*
* It must be redefined by child classes.
*
* @return true if the extension has been installed or a string explaining
* the problem.
*/
public function install() {}
public function install() {
return true;
}
/**
* Used when uninstalling an extension (e.g. revert the database scheme to
* cancel changes from install).
*
* It must be redefined by child classes.
*
* @return true if the extension has been uninstalled or a string explaining
* the problem.
*/
public function uninstall() {}
public function uninstall() {
return true;
}
/**
* Call at the initialization of the extension (i.e. when the extension is