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
Conversation
…fig file when run during installation
I made a mistake, it was only for commit 8f4fb4a initially. But not so bad, things are related. 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 how would someone trigger the headless installation? |
{ | ||
if (self::systemCheck()) | ||
{ | ||
//Raise Error because DigntosicService report in invalid. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
See #10257 (comment) for some explaination. It's using a MatomoInstall section in the config file.
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.
Think only about MatomoInstaller.php file, other files of the PR is for testing, to correct some small stuff incompatible with the installer etc. You can see the difference because between 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 |
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.
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 |
As an important extra, inside the |
@sgiehl maybe you can have a look at this PR tomorrow? |
There was a problem hiding this 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...
if (MatomoInstaller::isHeadlessInstall()) | ||
MatomoInstaller::installFromConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (MatomoInstaller::isHeadlessInstall()) | |
MatomoInstaller::installFromConfig(); | |
if (MatomoInstaller::isHeadlessInstall()) { | |
MatomoInstaller::installFromConfig(); | |
} |
if (self::systemCheck()) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (self::systemCheck()) | |
{ | |
if (self::systemCheck()) { |
if (MatomoInstaller::isHeadlessInstall()) | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (MatomoInstaller::isHeadlessInstall()) | |
return false; | |
if (MatomoInstaller::isHeadlessInstall()) { | |
return false; | |
} |
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class MatomoInstaller{ | |
class MatomoInstaller { |
public static function createDatabaseObject($settings) | ||
{ |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
@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. |
The "ExtraTools" plug-in has support for headless install: https://github.com/digitalist-se/extratools They use |
@AbcSxyZ are you going to update this PR any further or is the implementation in the ExtraTools plugin enough for you? |
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 !
And Matomo know this since years :) |
@AbcSxyZ Sorry to hear we weren't able to help you enough to get this PR finished. |
Diagnostic are runned at the beginning of the installation, and could be a better way to use specific function used for this purpose.