Remove deprecated tables and code

This commit is contained in:
Laurent Destailleur 2016-07-23 10:57:27 +02:00
parent f013656b02
commit 9c89bc4095
5 changed files with 4 additions and 366 deletions

View File

@ -1364,330 +1364,10 @@ class Holiday extends CommonObject
{
if (empty($userCP)) $userCP=0;
dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
/*
// On vérifie les users Dolibarr sans CP
if ($userDolibarrWithoutCP > 0)
{
$this->db->begin();
//$this->updateConfCP('nbUser',$userDolibarrWithoutCP);
$listUsersCP = $this->fetchUsers(true,false);
// On séléctionne les utilisateurs qui ne sont pas déjà dans le module
$sql = "SELECT u.rowid, u.lastname, u.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if ($listUsersCP != '') $sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")";
$resql = $this->db->query($sql);
if ($resql)
{
$i = 0;
$num = $this->db->num_rows($resql);
while($i < $num)
{
$obj = $this->db->fetch_object($resql);
$uid = $obj->rowid;
// On ajoute l'utilisateur
//print "Add user rowid = ".$uid." into database holiday";
$result = $this->createCPusers(true,$uid);
$i++;
}
$this->db->commit();
} else {
// Erreur SQL
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
else
{
$this->db->begin();
// Si il y a moins d'utilisateur Dolibarr que dans le module CP
$this->updateConfCP('nbUser',$userDolibarrWithoutCP);
$listUsersDolibarr = $this->fetchUsers(true,true);
// On séléctionne les utilisateurs qui ne sont pas déjà dans le module
$sql = "SELECT u.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as u";
$sql.= " WHERE u.fk_user NOT IN (".$listUsersDolibarr.")";
$resql = $this->db->query($sql);
// Si pas d'erreur SQL
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
while($i < $num) {
$obj = $this->db->fetch_object($resql);
// On supprime l'utilisateur
$this->deleteCPuser($obj->fk_user);
$i++;
}
$this->db->commit();
} else {
// Erreur SQL
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
*/
return 1;
}
/**
* Liste les évènements de congés payés enregistré
*
* @return int -1 si erreur, 1 si OK et 2 si pas de résultat
*/
function fetchEventsCP()
{
global $langs;
$sql = "SELECT";
$sql.= " cpe.rowid,";
$sql.= " cpe.name,";
$sql.= " cpe.value";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_events as cpe";
dol_syslog(get_class($this)."::fetchEventsCP", LOG_DEBUG);
$resql=$this->db->query($sql);
// Si pas d'erreur SQL
if ($resql) {
$i = 0;
$tab_result = $this->events;
$num = $this->db->num_rows($resql);
// Si pas d'enregistrement
if(!$num) {
return 2;
}
// On liste les résultats et on les ajoutent dans le tableau
while($i < $num) {
$obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['name'] = $obj->name;
$tab_result[$i]['value'] = $obj->value;
$i++;
}
// Retourne 1 et ajoute le tableau à la variable
$this->events = $tab_result;
return 1;
}
else
{
// Erreur SQL
$this->error="Error ".$this->db->lasterror();
return -1;
}
}
/**
* Créer un évènement de congés payés
*
* @param User $user User
* @param int $notrigger No trigger
* @return int -1 si erreur, id si OK
*/
function createEventCP($user, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_events (";
$sql.= "name,";
$sql.= "value";
$sql.= ") VALUES (";
$sql.= " '".$this->db->escape($this->optName)."',";
$sql.= " '".$this->optValue."'";
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::createEventCP", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql) {
$error++; $this->errors[]="Error ".$this->db->lasterror();
}
if (! $error)
{
$this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_events");
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::createEventCP ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return $this->optRowid;
}
}
/**
* Met à jour les évènements de congés payés
*
* @param int $rowid Row id
* @param string $name Name
* @param value $value Value
* @return int -1 si erreur, id si OK
*/
function updateEventCP($rowid, $name, $value) {
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_events SET";
$sql.= " name = '".$this->db->escape($name)."', value = '".$value."'";
$sql.= " WHERE rowid = '".$rowid."'";
$result = $this->db->query($sql);
if($result) {
return true;
}
return false;
}
/**
* Select event
*
* @return string|false Select Html to select type of holiday
*/
function selectEventCP()
{
$sql = "SELECT rowid, name, value";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_events";
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
$out = '<select name="list_event" class="flat" >';
$out.= '<option value="-1">&nbsp;</option>';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$out.= '<option value="'.$obj->rowid.'">'.$obj->name.' ('.$obj->value.')</option>';
$i++;
}
$out.= '</select>';
return $out;
}
else
{
return false;
}
}
/**
* deleteEvent
*
* @param int $rowid Row id
* @return boolean Success or not
*/
function deleteEventCP($rowid) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_events";
$sql.= " WHERE rowid = '".$rowid."'";
$result = $this->db->query($sql);
if($result) {
return true;
} else {
return false;
}
}
/**
* getValueEventCp
*
* @param int $rowid Row id
* @return string|false
*/
function getValueEventCp($rowid) {
$sql = "SELECT value";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_events";
$sql.= " WHERE rowid = '".$rowid."'";
$result = $this->db->query($sql);
if($result) {
$obj = $this->db->fetch_array($result);
return number_format($obj['value'],2);
} else {
return false;
}
}
/**
* getNameEventCp
*
* @param int $rowid Row id
* @return unknown|boolean
*/
function getNameEventCp($rowid) {
$sql = "SELECT name";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_events";
$sql.= " WHERE rowid = '".$rowid."'";
$result = $this->db->query($sql);
if($result) {
$obj = $this->db->fetch_array($result);
return $obj['name'];
} else {
return false;
}
}
/**
* addLogCP
*

View File

@ -186,6 +186,7 @@ if (is_numeric($listUsers) && $listUsers < 0)
$var=true;
$i = 0;
/*
$cp_events = $holiday->fetchEventsCP();
if ($cp_events == 1)
{
@ -202,7 +203,7 @@ if ($cp_events == 1)
print '</form><br>';
}
*/
$typeleaves=$holiday->getTypes(1,1);

View File

@ -36,6 +36,8 @@ ALTER TABLE llx_ecm_files ADD COLUMN gen_or_uploaded varchar(12) after cover;
DROP TABLE llx_document_generator;
DROP TABLE llx_ecm_documents;
DROP TABLE llx_holiday_events;
DROP TABLE llx_holiday_types;
ALTER TABLE llx_notify ADD COLUMN type_target varchar(16) NULL;

View File

@ -1,19 +0,0 @@
-- ===================================================================
-- Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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 3 of the License, or
-- (at your option) any later version.
--
-- 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/>.
--
-- ===================================================================
ALTER TABLE llx_holiday_events ADD UNIQUE INDEX uk_holiday_name (name, entity);

View File

@ -1,26 +0,0 @@
-- ===================================================================
-- Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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 3 of the License, or
-- (at your option) any later version.
--
-- 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/>.
--
-- ===================================================================
CREATE TABLE llx_holiday_events
(
rowid integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
entity integer DEFAULT 1 NOT NULL, -- multi company id
name VARCHAR( 255 ) NOT NULL,
value TEXT NOT NULL
)
ENGINE=innodb;