-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInit.php
More file actions
76 lines (70 loc) · 2.77 KB
/
Init.php
File metadata and controls
76 lines (70 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* This file is part of OpenServBus plugin for FacturaScripts
* Copyright (C) 2021-2023 Carlos Garcia Gomez <carlos@facturascripts.com>
* Copyright (C) 2021 Jerónimo Pedro Sánchez Manzano <socger@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
namespace FacturaScripts\Plugins\OpenServBus;
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Base\InitClass;
use FacturaScripts\Plugins\OpenServBus\Model\Service;
use FacturaScripts\Plugins\OpenServBus\Model\ServiceRegular;
final class Init extends InitClass
{
public function init()
{
// se ejecuta cada vez que carga FacturaScripts (si este plugin está activado).
$this->loadExtension(new Extension\Controller\EditRole());
$this->loadExtension(new Extension\Controller\EditUser());
}
public function update()
{
new Service();
new ServiceRegular();
$this->deleteColumnFromTable();
$this->changeNameEmployee();
}
private function changeNameEmployee()
{
// cambiamos el nombre de la tabla employees por employees_open
// al actualizar a la versión 3.1
$dataBase = new DataBase();
if ($dataBase->tableExists('employees')) {
$sql = "ALTER TABLE employees RENAME employees_open";
$dataBase->exec($sql);
}
}
protected function deleteColumnFromTable()
{
// eliminamos las columnas deseadas de las tablas seleccionadas
// al actualizar a la versión 3.0
$dataBase = new DataBase();
$columns = ['nombre'];
$tables = ['employee_contracts', 'employees_attendance_management_yn', 'drivers', 'helpers', 'collaborators'];
foreach ($tables as $table) {
// preguntamos si existe la tabla
if (false === $dataBase->tableExists($table)) {
continue;
}
foreach ($dataBase->getColumns($table) as $column) {
if (in_array($column['name'], $columns)) {
$sql = 'ALTER TABLE ' . $table . ' DROP COLUMN ' . $column['name'];
$dataBase->exec($sql);
}
}
}
}
}