Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatomoInstaller : headless installation of matomo #15691

Closed
wants to merge 3 commits into from
Closed

MatomoInstaller : headless installation of matomo #15691

wants to merge 3 commits into from

Conversation

AbcSxyZ
Copy link

@AbcSxyZ AbcSxyZ commented Mar 12, 2020

Diagnostic are runned at the beginning of the installation, and could be a better way to use specific function used for this purpose.

@Findus23 Findus23 added the Needs Review PRs that need a code review label Mar 12, 2020
@AbcSxyZ
Copy link
Author

AbcSxyZ commented Mar 13, 2020

I made a mistake, it was only for commit 8f4fb4a initially. But not so bad, things are related.
I didn't thought pushing to my repo would also add new commit to the PR...

I worked on a feature : #10257 , about Matomo installation in a automated way.

It's for me the beginning of a feature who must be review and adjusted, I wasn't able to manage all. I tried to create it as a depedent block, I juste add it to Matomo in a temporary way (5bb4565) for testing.

Please check issue, I added some comments (way to use). I know it's not finished, I think it can be a good point to start with, I tried to do as most as possible for me for the moment (I never used Matomo, don't know some cases). It can be for a new branch.

@AbcSxyZ AbcSxyZ changed the title plugin diagnostic: use SettingsPiwik::isMatomoInstalled [DRAFT] MatomoInstaller : headless installation of matomo Mar 13, 2020
@tsteur
Copy link
Member

tsteur commented May 13, 2020

@AbcSxyZ how would someone trigger the headless installation?

{
if (self::systemCheck())
{
//Raise Error because DigntosicService report in invalid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems there is something to do?

* - url
* - ecommerce : (optionnal)
*/
public static function headlessInstall($settings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw ideally we would put these things maybe in a command so someone can specifically trigger the headless installation? We could create a command class and then add this command to https://github.com/matomo-org/matomo/blob/4.x-dev/core/Console.php#L270 so it's available even before any Matomo is installed . Or alternatively such a command be defined in a plugin and then we'd need to configure that plugin name in [General]always_load_commands_from_plugin setting.

@AbcSxyZ
Copy link
Author

AbcSxyZ commented May 13, 2020

@AbcSxyZ how would someone trigger the headless installation?

See #10257 (comment) for some explaination. It's using a MatomoInstall section in the config file.

seems there is something to do?

Like I said, I'm not a user of matomo, so there is multiple point that I don't know how to do. I commented out those point and it's necessary to dive into the code again with someone who know matomo.

btw ideally we would put these things maybe in a command so someone can specifically trigger the headless installation?

Think only about MatomoInstaller.php file, other files of the PR is for testing, to correct some small stuff incompatible with the installer etc.
I was more thinking about it as a core feature, who can be used for any installation (and could be an helper for the actual one).

You can see the difference because between MatomoInstaller::headlessInstall and Matomo::installFromConfig have their own purpose. headlessInstall function just get all parameters, and perform the installation. installFromConfig retrieve the settings inside the MatomoInstaller section of the config file, and give them to the headlessInstall.

So what I had in mind is to allow the user to perform the installation in any way he want. He just have to define his own way to retrieve data, and give them to the MatomoInstaller::headlessInstall. In this way you [Matomo devs] could create some default way to perform the installation (through config file for exemple) and allow the user to create custom method.

@tsteur tsteur added this to the 4.0.0 RC milestone May 13, 2020
@AbcSxyZ
Copy link
Author

AbcSxyZ commented May 15, 2020

Because there is a lot of edited files (7 files), I will add explaination about all of them, to detail what are purpose of the modification, hope it will be usefull.

  1. commit 8f4fb4afb1232d588d0615a794e6c313b86ed0ff, files plugins/Diagnostics/Diagnostic/{DbReaderCheck, ForceSSLCheck, NfsDiskCheck}.php (3/7)
    --> To launch diagnostic, it actually verify if matomo is installed by checking the local config file. Change it by using function SettingsPiwik::isMatomoInstalled designed for it, otherwise it create some conflict with a config file containing an installation section.

  2. commit a391f00436c8147bed254d0397438efa8dd2b164

    • file core/Db/Adapter.php (4/7)
      --> Create a function to get the default adapter instead of hardcoding it in the installer.
    • file core/MatomoInstaller.php (5/7) [THE MAIN FEATURE]
      --> Class to perform an entire installation. Actually divided by step like it is with the actual GUI (system check, databases installation, site creation ...). Mainly 2 extra function MatomoInstaller::headlessInstall and MatomoInstaller::installFromConfig, respectively used to perform all step from given settings and to retrieve settings within the config file.
  3. commit 5bb4565136fa3b06d18386b94d9ccf3be67a6f54

    • file core/SettingsPiwik.php (6/7)
      --> For SettingsPiwik::isMatomoInstalled, check if an headless install have to be performed.
    • file core/Application/Kernel/EnvironmentValidator.php (7/7)
      --> Perform the MatomoInstaller::installFromConfig. Probably not the best place to perform this call, but this allowed me to test the installer. From my memory, I was a bit lost because the environnement is called from multiple place, and it was working when called from here. It's like glue.

I hope all comments and this will help to understand my work. Remember, I'm nor a php dev, nor a matomo user so there is multiple unknow stuff to me who could (should ?) be improve. Also in multiple place, I didn't know how to deal with some errors (it should be commented within the code). Finally, to avoid duplicating code, the actual GUI installation could call function from the installer because each installation step is a function of the MatomoInstaller. Because it's important feature, I didn't add those modification to the PR, to let the headless installation being a standalone feature, but those modification should be performed at short or long term.

@AbcSxyZ
Copy link
Author

AbcSxyZ commented May 15, 2020

As an important extra, inside the MatomoInstaller, or the installer himself, it have to be rethink to allow inheritance of a couple of functions, at least MatomoInstall::isHeadlessInstall, to let the user adding custom installation methods.

@Findus23 Findus23 marked this pull request as draft June 15, 2020 11:32
@Findus23 Findus23 changed the title [DRAFT] MatomoInstaller : headless installation of matomo MatomoInstaller : headless installation of matomo Jun 15, 2020
@tsteur tsteur requested a review from sgiehl November 2, 2020 21:52
@tsteur
Copy link
Member

tsteur commented Nov 2, 2020

@sgiehl maybe you can have a look at this PR tomorrow?

Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments, some of them only re coding style.

In general I agree with @tsteur. It might be more useful to have that in a command instead of having a magic process that is triggered automatically once Matomo is opened.

The command could work with a given ini file (doesn't need to be Matomos config), or with command line parameters or if anything is missing the command could even ask for a value...

Comment on lines +63 to +64
if (MatomoInstaller::isHeadlessInstall())
MatomoInstaller::installFromConfig();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (MatomoInstaller::isHeadlessInstall())
MatomoInstaller::installFromConfig();
if (MatomoInstaller::isHeadlessInstall()) {
MatomoInstaller::installFromConfig();
}

Comment on lines +62 to +63
if (self::systemCheck())
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (self::systemCheck())
{
if (self::systemCheck()) {

Comment on lines +224 to +225
if (MatomoInstaller::isHeadlessInstall())
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (MatomoInstaller::isHeadlessInstall())
return false;
if (MatomoInstaller::isHeadlessInstall()) {
return false;
}

Comment on lines +196 to +217
try {
@Db::createDatabaseObject($dbInfos);
} catch (Zend_Db_Adapter_Exception $e) {
$db = Adapter::factory($adapter, $dbInfos, $connect = false);

// database not found, we try to create it
if ($db->isErrNo($e, '1049')) {
$dbInfosConnectOnly = $dbInfos;
$dbInfosConnectOnly['dbname'] = null;
@Db::createDatabaseObject($dbInfosConnectOnly);
@DbHelper::createDatabase($dbInfos['dbname']);

/* // select the newly created database */
@Db::createDatabaseObject($dbInfos);
} else {
throw $e;
}
}

@DbHelper::checkDatabaseVersion();

@Db::get()->checkClientVersion();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try to avoid using @ so often. If something might throw an Error\Exception us try/catch instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was like that in the previous version. It seems installation process change since I did it (https://github.com/matomo-org/matomo/blob/4.x-dev/plugins/Installation/Controller.php)

* installation process?)
*/

class MatomoInstaller{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class MatomoInstaller{
class MatomoInstaller {

Comment on lines +146 to +147
public static function createDatabaseObject($settings)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it would be better to directly configure the database in the database section instead of the new Installer section. The Installer could simply check if the database is configured correctly and if no tables exist yet, the installer could create them...

/**
* Installation Step 5: General Set-up (superuser login/password/email and subscriptions)
*/
public static function setupSuperUser($settings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for having all methods static? Imho it would be better to have them non-static. Additionally I would set the settings as private property in __construct maybe and use that in all methods instead of passing it to every method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a php developper, and I had some problem with the a php feature where you store initialized class, so I made it like that. Everything can be improve.

//S: Should I perform the system check ?
//In : https://github.com/digitalist-se/extratools/blob/master/Lib/Install.php
// no system check seem to be performed.
public static function systemCheck($view=null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When moved to a command, we could output the error results and maybe ask the user if the installation should be aborted or continued nevertheless.

@AbcSxyZ
Copy link
Author

AbcSxyZ commented Nov 11, 2020

@sgiehl I don't know what is the best way to perform installation (command or ini file), the idea was also to let any user create a custom install method. So you can choose one default method to allow an headless install, and let the user specify if needed.

So I don't know which method would be the best. But in my mind, you can't create a new installation method without (at short or long term) modifying the installation process inside the core. You GUI installation and command installation should call the same interface, otherwise you will have duplicate code.

@bluikko
Copy link

bluikko commented Nov 13, 2020

The "ExtraTools" plug-in has support for headless install: https://github.com/digitalist-se/extratools

They use console matomo:install to install. It would be great if Matomo could provide headless install out of the box.

@tsteur tsteur modified the milestones: 4.0.0-RC, 4.1.0 Nov 16, 2020
@mattab mattab modified the milestones: 4.1.0, 4.2.0 Dec 21, 2020
@sgiehl
Copy link
Member

sgiehl commented Jan 14, 2021

@AbcSxyZ are you going to update this PR any further or is the implementation in the ExtraTools plugin enough for you?

@sgiehl sgiehl added the Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. label Jan 14, 2021
@AbcSxyZ
Copy link
Author

AbcSxyZ commented Jan 14, 2021

I won't do it, I just used Matomo once, I was more trying to contribute to an open source project by the time. It took too long to get an answer, I was expecting some help, I'm not involved anymore. Some disappointment honestly.

So I don't care if this PR is deleted or whatever, but if I were a matomo user I would prefer to have a headless installation rather than a plugin to perform that !

It would be great if Matomo could provide headless install out of the box.
@bluikko

And Matomo know this since years :)
Wish you the best for those who will work on that, will be a huge improvement from my point of view.

@sgiehl
Copy link
Member

sgiehl commented Jan 15, 2021

@AbcSxyZ Sorry to hear we weren't able to help you enough to get this PR finished.
Thanks anyway for your effort!
I will close this PR for now, as we won't be working on it soon. If anyone else is keen on implementing this, feel free to use some parts of the changes in this PR to reopen a new one.
Everything else about headless installed will be handled in the issue #10257

@sgiehl sgiehl closed this Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants