Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2020-05-14 18:26:56 +0300
committerGitHub <noreply@github.com>2020-05-14 18:26:56 +0300
commitdc4c4947d0f3d9e193be4191c963b55c6018d6a2 (patch)
treeee869886d568ff363c0d84b7092899b4405bf6d7 /plugins/GeoIp2/GeoIp2.php
parente2c98248f71a91d8b57c92ed72a4b8d68539584d (diff)
Make it possible to automatically set up geoip2 in installation (#15939)
* make it possible to automatically set up geoip2 in installation * reenable skipped installation ui tests * updates expected UI files * do download in hourly task * trigger an async run of scheduled tasks to set up geoip2 * directly execute the task if possible and schedule the task only if not * improve text * updates UI test
Diffstat (limited to 'plugins/GeoIp2/GeoIp2.php')
-rw-r--r--plugins/GeoIp2/GeoIp2.php64
1 files changed, 62 insertions, 2 deletions
diff --git a/plugins/GeoIp2/GeoIp2.php b/plugins/GeoIp2/GeoIp2.php
index ffba09bd98..2f1c2e6748 100644
--- a/plugins/GeoIp2/GeoIp2.php
+++ b/plugins/GeoIp2/GeoIp2.php
@@ -8,7 +8,13 @@
*/
namespace Piwik\Plugins\GeoIp2;
+use Piwik\CliMulti;
+use Piwik\Container\StaticContainer;
+use Piwik\Option;
+use Piwik\Piwik;
+use Piwik\Plugins\Installation\FormDefaultSettings;
use Piwik\Plugins\UserCountry\LocationProvider;
+use Piwik\Scheduler\Scheduler;
/**
*
@@ -18,8 +24,10 @@ class GeoIp2 extends \Piwik\Plugin
public function registerEvents()
{
return array(
- 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
- 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
+ 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
+ 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
+ 'Installation.defaultSettingsForm.init' => 'installationFormInit',
+ 'Installation.defaultSettingsForm.submit' => 'installationFormSubmit',
);
}
@@ -50,4 +58,56 @@ class GeoIp2 extends \Piwik\Plugin
$translationKeys[] = "General_Save";
$translationKeys[] = "General_Continue";
}
+
+ /**
+ * Customize the Installation "default settings" form.
+ *
+ * @param FormDefaultSettings $form
+ */
+ public function installationFormInit(FormDefaultSettings $form)
+ {
+ $form->addElement('checkbox', 'setup_geoip2', null,
+ [
+ 'content' => '<div class="form-help">' . Piwik::translate('GeoIp2_AutomaticSetupDescription', ['<a rel="noreferrer noopener" href="https://db-ip.com/?refid=mtm">','</a>']) . '</div> &nbsp;&nbsp;' . Piwik::translate('GeoIp2_AutomaticSetup')
+ ]
+ );
+
+ // default values
+ $form->addDataSource(new \HTML_QuickForm2_DataSource_Array([
+ 'setup_geoip2' => true,
+ ]));
+ }
+
+ /**
+ * Process the submit on the Installation "default settings" form.
+ *
+ * @param FormDefaultSettings $form
+ */
+ public function installationFormSubmit(FormDefaultSettings $form)
+ {
+ $setupGeoIp2 = (bool) $form->getSubmitValue('setup_geoip2');
+
+ if ($setupGeoIp2) {
+ Option::set(GeoIP2AutoUpdater::AUTO_SETUP_OPTION_NAME, true);
+ GeoIP2AutoUpdater::setUpdaterOptions([
+ 'loc' => \Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2::getDbIpLiteUrl(),
+ 'period' => GeoIP2AutoUpdater::SCHEDULE_PERIOD_MONTHLY
+ ]);
+
+ $cliMulti = new CliMulti();
+
+ // directly trigger the update task if possible
+ // otherwise ensure it will be run soonish as scheduled task
+ if ($cliMulti->supportsAsync()) {
+ $phpCli = new CliMulti\CliPhp();
+ $command = sprintf('%s %s/console core:run-scheduled-tasks --force "Piwik\Plugins\GeoIp2\GeoIP2AutoUpdater.update" > /dev/null 2>&1 &',
+ $phpCli->findPhpBinary(), PIWIK_INCLUDE_PATH);
+ shell_exec($command);
+ } else {
+ /** @var Scheduler $scheduler */
+ $scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
+ $scheduler->rescheduleTask(new GeoIP2AutoUpdater());
+ }
+ }
+ }
}