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

Php7 migration clapi #6368

Merged
merged 22 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b520d4c
fix(export): Filter type work with CG
Jun 1, 2018
9d68129
fix(export): Select specific HC resource filters now
Jun 1, 2018
ba3d8ac
fix(clapi): apply filters on service category export
kduret Jun 6, 2018
668bd8b
refacto(clapi): begin refacto of clapi export
kduret Jun 6, 2018
aa1e41a
refacto(clapi): step 2 of clapi export refacto
kduret Jun 6, 2018
40d09ce
refacto(clapi): refacto export of centreon clapi
kduret Jun 7, 2018
5906f74
refacto(clapi): refacto export of centreon clapi
kduret Jun 7, 2018
d7bcec7
fix(clapi): fix export of contact groups
kduret Jun 7, 2018
a9bbd7c
fix(api): update require path in contact template
kduret Jun 7, 2018
2b1ab8a
fix(api): fix export of HG and SG
kduret Jun 7, 2018
15a7799
refacto(clapi): avoid duplicate object export
kduret Jun 7, 2018
088ebe3
refacto(clapi): fix service and contact template export
kduret Jun 7, 2018
68059de
refacto(clapi): fix php warnings
kduret Jun 7, 2018
4232af7
fix(comments): fix comments in clapi timezone object
kduret Jun 7, 2018
ad3c746
fix(style): fix variable name (lower camelcase)
kduret Jun 7, 2018
d0e4a2e
refacto(clapi): update default parameter of export method
kduret Jun 11, 2018
5b19b53
fix(clapi) dependency injector
loiclau Jun 13, 2018
6c534e8
fix(clapi) compatibility parent/child
loiclau Jun 14, 2018
2365c10
fix(clapi) fix filter by object
loiclau Jun 14, 2018
6ccb986
fix(clapi) fix lib compatibility parent/child
loiclau Jun 14, 2018
34d8ecf
fix(clapi) order export
loiclau Jun 15, 2018
fe8bf85
fix(clapi) clean unused local variable
loiclau Jun 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lib/Centreon/Object/Relation/Host/Template/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public function __construct(\Pimple\Container $dependencyInjector)
* @param int $skey
* @return void
*/
public function insert($fkey, $skey)
public function insert($fkey, $skey = null)
{
$sql = "SELECT MAX(`order`) as maxorder FROM " .$this->relationTable . " WHERE " .$this->secondKey . " = ?";
$sql = "SELECT MAX(`order`) as maxorder FROM " . $this->relationTable . " WHERE " . $this->secondKey . " = ?";
$res = $this->db->query($sql, array($skey));
$row = $res->fetch();
$order = 1;
if (isset($row['maxorder'])) {
$order = $row['maxorder']+1;
$order = $row['maxorder'] + 1;
}
unset($res);
$sql = "INSERT INTO $this->relationTable ($this->firstKey, $this->secondKey, `order`) VALUES (?, ?, ?)";
Expand Down Expand Up @@ -104,8 +104,16 @@ public function getTargetIdFromSourceId($targetKey, $sourceKey, $sourceId)
* @param string $filterType
* @return array
*/
public function getMergedParameters($firstTableParams = array(), $secondTableParams = array(), $count = -1, $offset = 0, $order = null, $sort = "ASC", $filters = array(), $filterType = "OR")
{
public function getMergedParameters(
$firstTableParams = array(),
$secondTableParams = array(),
$count = -1,
$offset = 0,
$order = null,
$sort = "ASC",
$filters = array(),
$filterType = "OR"
) {
if (!isset($this->firstObject) || !isset($this->secondObject)) {
throw new Exception('Unsupported method on this object');
}
Expand All @@ -115,18 +123,18 @@ public function getMergedParameters($firstTableParams = array(), $secondTablePar
if ($fString != "") {
$fString .= ",";
}
$fString .= "h.".$fparams;
$fString .= "h." . $fparams;
}
foreach ($secondTableParams as $sparams) {
if ($fString != "" || $sString != "") {
$sString .= ",";
}
$sString .= "h2.".$sparams;
$sString .= "h2." . $sparams;
}
$sql = "SELECT ".$fString.$sString."
FROM ".$this->firstObject->getTableName()." h,".$this->relationTable."
JOIN ".$this->secondObject->getTableName(). " h2 ON ".$this->relationTable.".".$this->firstKey." = h2.".$this->secondObject->getPrimaryKey() ."
WHERE h.".$this->firstObject->getPrimaryKey()." = ".$this->relationTable.".".$this->secondKey;
$sql = "SELECT " . $fString . $sString . "
FROM " . $this->firstObject->getTableName() . " h," . $this->relationTable . "
JOIN " . $this->secondObject->getTableName() . " h2 ON " . $this->relationTable . "." . $this->firstKey . " = h2." . $this->secondObject->getPrimaryKey() . "
WHERE h." . $this->firstObject->getPrimaryKey() . " = " . $this->relationTable . "." . $this->secondKey;
$filterTab = array();
if (count($filters)) {
foreach ($filters as $key => $rawvalue) {
Expand Down
32 changes: 22 additions & 10 deletions lib/Centreon/Object/Relation/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,24 @@ public function getRelations()
* @param array $firstTableParams
* @param array $secondTableParams
* @param int $count
* @param string $order
* @param int $offset
* @param null $order
* @param string $sort
* @param array $filters
* @param string $filterType
* @return array
* @return false|mixed
* @throws Exception
*/
public function getMergedParameters($firstTableParams = array(), $secondTableParams = array(), $count = -1, $offset = 0, $order = null, $sort = "ASC", $filters = array(), $filterType = "OR")
{
public function getMergedParameters(
$firstTableParams = array(),
$secondTableParams = array(),
$count = -1,
$offset = 0,
$order = null,
$sort = "ASC",
$filters = array(),
$filterType = "OR"
) {
if (!isset($this->firstObject) || !isset($this->secondObject)) {
throw new Exception('Unsupported method on this object');
}
Expand All @@ -170,18 +180,20 @@ public function getMergedParameters($firstTableParams = array(), $secondTablePar
if ($fString != "") {
$fString .= ",";
}
$fString .= $this->firstObject->getTableName().".".$fparams;
$fString .= $this->firstObject->getTableName() . "." . $fparams;
}
foreach ($secondTableParams as $sparams) {
if ($fString != "" || $sString != "") {
$sString .= ",";
}
$sString .= $this->secondObject->getTableName().".".$sparams;
$sString .= $this->secondObject->getTableName() . "." . $sparams;
}
$sql = "SELECT ".$fString.$sString."
FROM ".$this->firstObject->getTableName().",".$this->secondObject->getTableName().",".$this->relationTable."
WHERE ".$this->firstObject->getTableName().".".$this->firstObject->getPrimaryKey()." = ".$this->relationTable.".".$this->firstKey."
AND ".$this->relationTable.".".$this->secondKey." = ".$this->secondObject->getTableName().".".$this->secondObject->getPrimaryKey();
$sql = "SELECT " . $fString . $sString . " FROM " . $this->firstObject->getTableName() . "," .
$this->secondObject->getTableName() . "," . $this->relationTable .
" WHERE " . $this->firstObject->getTableName() . "." .
$this->firstObject->getPrimaryKey() . " = " . $this->relationTable . "." . $this->firstKey .
" AND " . $this->relationTable . "." . $this->secondKey . " = " . $this->secondObject->getTableName() .
"." . $this->secondObject->getPrimaryKey();
$filterTab = array();
if (count($filters)) {
foreach ($filters as $key => $rawvalue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ class Centreon_Object_Relation_Service_Group_Host_Group_Service extends Centreon

/**
* Used for inserting relation into database
*
* @param int $fkey
* @param int $hgId
* @param int $serviceId
* @return void
* @param null $key
*/
public function insert($fkey, $hgId, $serviceId)
public function insert($fkey, $key = null)
{
$hgId = $key['hostId'];
$serviceId = $key['serviceId'];
$sql = "INSERT INTO $this->relationTable ($this->firstKey, hostgroup_hg_id, $this->secondKey) VALUES (?, ?, ?)";
$this->db->query($sql, array($fkey, $hgId, $serviceId));
}
Expand Down Expand Up @@ -123,7 +122,7 @@ public function getHostGroupIdServiceIdFromServicegroupId($servicegroupId)
* @param array $arg
* @throws Exception
*/
public function __call($name, $arg)
public function __call($name, $arg = array())
{
throw new Exception('Unknown method');
}
Expand Down
11 changes: 5 additions & 6 deletions lib/Centreon/Object/Relation/Service/Group/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ class Centreon_Object_Relation_Service_Group_Service extends Centreon_Object_Rel

/**
* Used for inserting relation into database
*
* @param int $fkey
* @param int $hostId
* @param int $serviceId
* @return void
* @param null $key
*/
public function insert($fkey, $hostId, $serviceId)
public function insert($fkey, $key = null)
{
$hostId = $key['hostId'];
$serviceId = $key['serviceId'];
$sql = "INSERT INTO $this->relationTable ($this->firstKey, host_host_id, $this->secondKey) VALUES (?, ?, ?)";
$this->db->query($sql, array($fkey, $hostId, $serviceId));
}
Expand Down Expand Up @@ -123,7 +122,7 @@ public function getHostIdServiceIdFromServicegroupId($servicegroupId)
* @param array $arg
* @throws Exception
*/
public function __call($name, $arg)
public function __call($name, $arg = array())
{
throw new Exception('Unknown method');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Centreon/Object/Relation/Service/Template/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(\Pimple\Container $dependencyInjector)
* @param int $skey
* @return void
*/
public function insert($fkey, $skey)
public function insert($fkey, $skey = null)
{
$sql = "INSERT INTO $this->relationTable ($this->secondKey, $this->firstKey) VALUES (?, ?)";
$this->db->query($sql, array($fkey, $skey));
Expand Down Expand Up @@ -147,7 +147,7 @@ public function getMergedParameters($firstTableParams = array(), $secondTablePar
* @param int $skey
* @return void
*/
public function delete($fkey, $skey)
public function delete($fkey, $skey = null)
{
if (isset($fkey) && isset($skey)) {
$sql = "DELETE FROM $this->relationTable WHERE $this->firstKey = ? AND $this->secondKey = ?";
Expand Down
13 changes: 3 additions & 10 deletions www/class/centreon-clapi/centreon.Config.Poller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,17 @@ protected function restartCentreonBroker()
}

/**
*
* Reload a server
* @param unknown_type $variables
* @param $variables
* @return mixed
*/
public function pollerReload($variables)
{
$return_value = 0;

if (!isset($variables)) {
print "Cannot get poller";
exit(1);
}

$poller_id = $this->getPollerId($variables);

$this->testPollerId($poller_id);

/*
Expand Down Expand Up @@ -295,7 +291,6 @@ public function pollerRestart($variables)
}

$this->testPollerId($variables);

$poller_id = $this->getPollerId($variables);

/*
Expand All @@ -322,7 +317,6 @@ public function pollerRestart($variables)
$host = $DBRESULT->fetchRow();
$DBRESULT->closeCursor();

$msg_restart = "";
if (isset($host['localhost']) && $host['localhost'] == 1) {
$msg_restart = exec(
escapeshellcmd("sudo service " . $nagios_init_script . " restart"),
Expand All @@ -334,7 +328,7 @@ public function pollerRestart($variables)
$msg_restart = _("OK: A restart signal has been sent to '" . $host["name"] . "'");
}
print $msg_restart . "\n";
$DBRESULT = $this->_DB->query(
$this->_DB->query(
"UPDATE `nagios_server` SET `last_restart` = '" . time()
. "' WHERE `id` = '" . $this->_DB->escape($poller_id) . "' LIMIT 1"
);
Expand Down Expand Up @@ -641,7 +635,6 @@ public function cfgMove($variables)
public function getApacheUser()
{
/* Change files owner */
$setFilesOwner = 1;
$installFile = "/etc/centreon/instCentWeb.conf";

if (file_exists($installFile)) {
Expand Down
Loading