Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(clapi): require the root bootstrap.php breaks some class loading #11476

Closed

Conversation

proxyconcept
Copy link

…(#11434)

Class centreonContact is the only to require 'bootstrap.php' but then other import can failed with class not found exception.
But if the root 'bootstrap.php' is not loaded, we must at least redefine the function loadDependencyInjector().

Refs: #11434
Signed-off-by: Grégory Marigot gmarigot@teicee.com

Description

Importing with CLAPI can failed with a "class not found" exception.

It seems to failed with lines that can be imported successfully when they are alone. The responsability could be a precedent import line with CONTACT or CONTACTTPL object. So I suspect the class centreonContact to break class loading for some next objects.

By studying the code in centreonContact.class.php i found curious the require_once DIR . '/../../../bootstrap.php'; because it was the only class in centreon-clapi to do it...

Removing this require solves the problems, but some other cases fail because they need the function loadDependencyInjector (defined in the bootstrap.php). So this function definition is also added in centreonAPI.php.

Fixes #11434

Type of change

  • Patch fixing an issue (non-breaking change)
  • New functionality (non-breaking change)
  • Breaking change (patch or feature) that might cause side effects breaking part of the Software

Target serie

  • 21.04.x
  • 21.10.x
  • 22.04.x
  • 22.10.x (master)

How this pull request can be tested ?

This is a sample file to import:

CONTACT;ADD;Notify-by-email-workhours;Notify-by-email-workhours;mail@example.org;p4ssw0rd@TEST;0;1;browser;local
STPL;addcontactgroup;default_notification;Guest

Which failed without this PR:

PHP Fatal error:  Uncaught Error: Class "Centreon_Object_Service" not found in /usr/share/centreon/www/class/centreon-clapi/centreonServiceTemplate.class.php:88
Stack trace:
#0 /usr/share/centreon/www/class/centreon-clapi/centreonAPI.class.php(980): CentreonClapi\CentreonServiceTemplate->__construct()
#1 /usr/share/centreon/www/class/centreon-clapi/centreonAPI.class.php(845): CentreonClapi\CentreonAPI->iniObject()
#2 /usr/share/centreon/www/class/centreon-clapi/centreonAPI.class.php(815): CentreonClapi\CentreonAPI->launchActionForImport()
#3 /usr/share/centreon/bin/centreon(196): CentreonClapi\CentreonAPI->import()
#4 {main}
  thrown in /usr/share/centreon/www/class/centreon-clapi/centreonServiceTemplate.class.php on line 88

I have tested a full export/import successfully with this patch.

Checklist

Community contributors & Centreon team

  • I have followed the coding style guidelines provided by Centreon
  • I have commented my code, especially new classes, functions or any legacy code modified. (docblock)
  • I have commented my code, especially hard-to-understand areas of the PR.
  • I have rebased my development branch on the base branch (master, maintenance).

emabassi-ext and others added 18 commits July 29, 2022 09:01
…centreon#11394)

* Sanitize and bind ACL host dependency queries

* fix issues
…entreon#11352)

Co-authored-by: jeremyjaouen <61694165+jeremyjaouen@users.noreply.github.com>
* sanitizing and binding sync dir file queries

* Applying some fixes
…tion (centreon#11440)

* fix(UI): Fix layout for Safari and form validation (centreon#11373)

* Fix form validation

* Fix padlock layout for safari

* Update centreon-frontend

* Remove debug variable

* Fix test

* Fix page respsoniveness

* Rename variable

* update deps

* Fix package-lock

* Fix package-lock

* Add debug statement for debian

* Install nodejs rather npm

* Attempt fix

* Attempt to fix nodejs installation

* add sudo

* Fix redoc-cli usage

* Try to fix permission on npm

* Fix

* Fix permission

* Fix permission (please work)

* Fix source

* Stop using npx because.....

* Allow legacy-peer-deps

* Remove nodejs installation

* Fix image to pull for debian 11
…entreon#11402)

* Sanitize and bind ACL action access queries

_ sanitize if possible each variables inserted in a query

_ use PDO prepared statement and bind() method

_ Do not use $pearDB->escape on which is for examples useless on integers and on non closed HTML tags (svg, img, etc)

* fix line length

* fix failed checks
* Clean(platform): Clean appKey method and usage (centreon#11336)

* removing appKey from information table in baseConf and 22.10 update script

* removing appKey from NotifyMasterService.php

* removing appKey from CentreonRemoteServer.php

* applying suggested changes

* Applying suggested changes

Co-authored-by: Kevin Duret <kduret@centreon.com>

* adding 22.04.2 update script file with changes

* revert 22.04 beta 1 script to its original

Co-authored-by: Kevin Duret <kduret@centreon.com>
…tion form 22.04.x (centreon#11461)

* changing select with select2 of metrics

* fix alignement

* remove unecessary files and replace selec by select2 in formComponentTemplate

* fix select id name for acceptance tests

* update composer for acceptance tests

* fix acceptance test 2

* add allow clear to metrics select2

* applying suggested changes

* final changes for merging

* remove unecessary select tag
…#11472)

* Sanitize and bind ACL class queries

Queries   sanitized  and bound using PDO statement

* fix spaces

spaces between (int) cast and variables

* update file delete spaces after comma

* change variables names due to a review

* Line exceeds 120 characters; contains 123 characters
…entreon#11434)

Class centreonContact is the only to require 'bootstrap.php' but then other import can failed with class not found exception.
But if the root 'bootstrap.php' is not loaded, we must at least redefine the function loadDependencyInjector().

Refs: centreon#11434
Signed-off-by: Grégory Marigot <gmarigot@teicee.com>
@proxyconcept proxyconcept requested review from a team, TamazC and wtermellil and removed request for a team August 1, 2022 08:31
@proxyconcept proxyconcept requested review from a team, bdauria and Jordan91 and removed request for a team August 4, 2022 09:14
@sonarqube-decoration
Copy link

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell D 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kduret
Copy link
Contributor

kduret commented Aug 8, 2022

thanks for your contribution @proxyconcept
I close this PR cause it's fixed here https://github.com/centreon/centreon/pull/11492

@kduret kduret closed this Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants