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

Commit

Permalink
fix(DB): upgrade DB to correct a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sc979 committed Jun 14, 2018
1 parent 693edc2 commit b330aee
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
109 changes: 109 additions & 0 deletions www/install/php/Update-2.8.23_to_2.8.24.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/*
* Copyright 2005-2018 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation ; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses>.
*
* Linking this program statically or dynamically with other modules is making a
* combined work based on this program. Thus, the terms and conditions of the GNU
* General Public License cover the whole combination.
*
* As a special exception, the copyright holders of this program give Centreon
* permission to link this program with independent modules to produce an executable,
* regardless of the license terms of these independent modules, and to copy and
* distribute the resulting executable under terms of Centreon choice, provided that
* Centreon also meet, for each linked independent module, the terms and conditions
* of the license of that module. An independent module is a module which is not
* derived from this program. If you modify this program, you may extend this
* exception to your version of the program, but you are not obliged to do so. If you
* do not wish to do so, delete this exception statement from your version.
*
* For more information : contact@centreon.com
*
*
*/

/**
* Checking if the DB is already upgraded
*/
$needUpgrade = "false";

$unlockTable = 'UNLOCK TABLES';
$stmt = $pearDB->query($unlockTable);
$stmt = $pearDBO->query($unlockTable);

$showKeysQuery = 'SHOW FIELDS FROM centreon_acl';
$result = $pearDBO->query($showKeysQuery);

$row = array();
while ($row = $result->fetchRow()) {
if ($row['Key'] === "MUL") {
$needUpgrade = "true";
}
}

if ($needUpgrade === "true") {
/**
* Checking if centAcl.php is running and waiting for it to stop before locking cron_operation table
*/
for ($i = 0; $i < 180; $i++) {
$searchStatus = 'SELECT running FROM cron_operation WHERE `name` = \'centAcl.php\'';
$result = $pearDB->query($searchStatus);
$row = array();
while ($row = $result->fetchRow()) {
if ($row['running'] == "1") {
sleep(1);
} else {
$lockTable = 'LOCK TABLES cron_operation READ';
$stmt = $pearDB->query($lockTable);
break;
}
}
}

/**
* Retrieving index occurrences, dropping keys and centreon_acl data
*/
$stmt = $pearDBO->query($unlockTable);

$searchIndex = 'SHOW INDEX FROM centreon_acl WHERE Key_name LIKE \'index%\'';
$stmt = $pearDBO->query($searchIndex);

$queryValues = array();
while ($row = $result->fetchRow()) {
$queryValues[$row['Key_name']] = $row['Key_name'];
}

foreach ($queryValues as $key => $value) {
$dropQuery = 'ALTER TABLE centreon_acl DROP KEY ' . $value;
$stmt = $pearDBO->query($dropQuery);
}

$truncateQuery = 'TRUNCATE centreon_acl';
$stmt = $pearDBO->query($truncateQuery);

/**
* Updating DBs and reloading cron_operation
*/
$add_query = 'ALTER TABLE centreon_acl ADD PRIMARY KEY (`group_id`,`host_id`,`service_id`)';
$stmt = $pearDBO->query($add_query);

$stmt = $pearDB->query($unlockTable);

$updateQuery = 'UPDATE acl_groups SET acl_group_changed = 1';
$stmt = $pearDB->query($updateQuery);

require_once __DIR__ . '/../../../cron/centAcl.php';
}
?>
2 changes: 2 additions & 0 deletions www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Change version of Centreon
UPDATE `informations` SET `value` = '2.8.24' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.23' LIMIT 1;

0 comments on commit b330aee

Please sign in to comment.