Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GLPI
glpi
Commits
c3b757df
Commit
c3b757df
authored
Jan 07, 2021
by
Cédric Anne
Committed by
Johan Cwiklinski
Jan 07, 2021
Browse files
Prevent console commands to be executed if DB is not up-to-date
parent
5bd77827
Changes
8
Hide whitespace changes
Inline
Side-by-side
inc/console/abstractcommand.class.php
View file @
c3b757df
...
...
@@ -64,12 +64,19 @@ abstract class AbstractCommand extends Command implements GlpiCommandInterface {
protected
$output
;
/**
* Flag to indicate if command requires a
B
D connection.
* Flag to indicate if command requires a D
B
connection.
*
* @var boolean
*/
protected
$requires_db
=
true
;
/**
* Flag to indicate if command requires an up-to-date DB.
*
* @var boolean
*/
protected
$requires_db_up_to_date
=
true
;
protected
function
initialize
(
InputInterface
$input
,
OutputInterface
$output
)
{
$this
->
input
=
$input
;
...
...
@@ -199,4 +206,9 @@ abstract class AbstractCommand extends Command implements GlpiCommandInterface {
return
true
;
}
public
function
requiresUpToDateDb
():
bool
{
return
$this
->
requires_db
&&
$this
->
requires_db_up_to_date
;
}
}
inc/console/application.class.php
View file @
c3b757df
...
...
@@ -68,6 +68,13 @@ class Application extends BaseApplication {
*/
const
ERROR_MISSING_REQUIREMENTS
=
128
;
// start application codes at 128 be sure to be different from commands codes
/**
* Error code returned when DB is not up-to-date.
*
* @var integer
*/
const
ERROR_DB_OUTDATED
=
129
;
/**
* Pointer to $CFG_GLPI.
* @var array
...
...
@@ -224,6 +231,16 @@ class Application extends BaseApplication {
$begin_time
=
microtime
(
true
);
if
(
$command
instanceof
GlpiCommandInterface
&&
$command
->
requiresUpToDateDb
()
&&
(
!
array_key_exists
(
'dbversion'
,
$this
->
config
)
||
(
trim
(
$this
->
config
[
'dbversion'
])
!=
GLPI_SCHEMA_VERSION
)))
{
$output
->
writeln
(
'<error>'
.
__
(
'The version of the database is not compatible with the version of the installed files. An update is necessary.'
)
.
'</error>'
);
return
self
::
ERROR_DB_OUTDATED
;
}
if
(
$command
instanceof
GlpiCommandInterface
&&
$command
->
mustCheckMandatoryRequirements
()
&&
!
$this
->
checkCoreMandatoryRequirements
())
{
return
self
::
ERROR_MISSING_REQUIREMENTS
;
...
...
inc/console/command/glpicommandinterface.class.php
View file @
c3b757df
...
...
@@ -39,9 +39,16 @@ if (!defined('GLPI_ROOT')) {
interface
GlpiCommandInterface
{
/**
* Defines whether or mandatory requirements must be checked before running command.
* Defines whether or
not
mandatory requirements must be checked before running command.
*
* @return boolean
*/
public
function
mustCheckMandatoryRequirements
():
bool
;
/**
* Defines whether or not command requires an up-to-date database to be executed.
*
* @return boolean
*/
public
function
requiresUpToDateDb
():
bool
;
}
inc/console/database/abstractconfigurecommand.class.php
View file @
c3b757df
...
...
@@ -93,6 +93,8 @@ abstract class AbstractConfigureCommand extends AbstractCommand implements Force
*/
const
ERROR_DB_CONFIG_FILE_NOT_SAVED
=
4
;
protected
$requires_db_up_to_date
=
false
;
protected
function
configure
()
{
parent
::
configure
();
...
...
inc/console/database/updatecommand.class.php
View file @
c3b757df
...
...
@@ -64,6 +64,8 @@ class UpdateCommand extends AbstractCommand implements ForceNoPluginsOptionComma
*/
const
ERROR_MISSING_SECURITY_KEY_FILE
=
2
;
protected
$requires_db_up_to_date
=
false
;
protected
function
configure
()
{
parent
::
configure
();
...
...
inc/console/maintenance/disablemaintenancemodecommand.class.php
View file @
c3b757df
...
...
@@ -44,6 +44,8 @@ use Symfony\Component\Console\Output\OutputInterface;
class
DisableMaintenanceModeCommand
extends
AbstractCommand
{
protected
$requires_db_up_to_date
=
false
;
protected
function
configure
()
{
parent
::
configure
();
...
...
inc/console/maintenance/enablemaintenancemodecommand.class.php
View file @
c3b757df
...
...
@@ -45,6 +45,8 @@ use Symfony\Component\Console\Output\OutputInterface;
class
EnableMaintenanceModeCommand
extends
AbstractCommand
{
protected
$requires_db_up_to_date
=
false
;
protected
function
configure
()
{
parent
::
configure
();
...
...
inc/console/system/clearcachecommand.class.php
View file @
c3b757df
...
...
@@ -42,6 +42,8 @@ use Symfony\Component\Console\Output\OutputInterface;
class
ClearCacheCommand
extends
Command
{
protected
$requires_db_up_to_date
=
false
;
protected
function
configure
()
{
parent
::
configure
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment