dolibarr 20.0.0
modules_import.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
27require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
28
29
34{
38 public $db;
39
40 public $datatoimport;
41
45 public $error = '';
46
50 public $errors = array();
51
55 public $warnings = array();
56
60 public $id;
61
65 public $label;
66
70 public $extension;
71
76 public $version = 'dolibarr';
77
82 public $phpmin = array(7, 0);
83
88 public $label_lib;
89
94 public $version_lib;
95
96 // Array of all drivers
97 public $driverlabel = array();
98
99 public $driverdesc = array();
100
101 public $driverversion = array();
102
103 public $drivererror = array();
104
105 public $liblabel = array();
106
107 public $libversion = array();
108
112 public $charset;
113
117 public $picto;
118
122 public $desc;
123
127 public $escape;
128
132 public $enclosure;
133
137 public $thirdpartyobject;
138
142 public static $mapTableToElement = MODULE_MAPPING;
143
147 public function __construct()
148 {
149 global $hookmanager;
150
151 if (is_object($hookmanager)) {
152 $hookmanager->initHooks(array('import'));
153 $parameters = array();
154 $reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
155 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
156 foreach ($hookmanager->resArray as $mapList) {
157 self::$mapTableToElement[$mapList['table']] = $mapList['element'];
158 }
159 }
160 }
161 }
162
168 public function getDriverId()
169 {
170 return $this->id;
171 }
172
178 public function getDriverLabel()
179 {
180 return $this->label;
181 }
182
188 public function getDriverDesc()
189 {
190 return $this->desc;
191 }
192
198 public function getDriverExtension()
199 {
200 return $this->extension;
201 }
202
208 public function getDriverVersion()
209 {
210 return $this->version;
211 }
212
218 public function getLibLabel()
219 {
220 return $this->label_lib;
221 }
222
228 public function getLibVersion()
229 {
230 return $this->version_lib;
231 }
232
233
241 public function listOfAvailableImportFormat($db, $maxfilenamelength = 0)
242 {
243 dol_syslog(get_class($this)."::listOfAvailableImportFormat");
244
245 $dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
246 $handle = opendir($dir);
247
248 // Search list ov drivers available and qualified
249 if (is_resource($handle)) {
250 while (($file = readdir($handle)) !== false) {
251 $reg = array();
252 if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) {
253 $moduleid = $reg[1];
254
255 // Loading Class
256 $file = $dir."/import_".$moduleid.".modules.php";
257 $classname = "Import".ucfirst($moduleid);
258
259 require_once $file;
260 $module = new $classname($db, '');
261
262 // Picto
263 $this->picto[$module->id] = $module->picto;
264 // Driver properties
265 $this->driverlabel[$module->id] = $module->getDriverLabel('');
266 $this->driverdesc[$module->id] = $module->getDriverDesc('');
267 $this->driverversion[$module->id] = $module->getDriverVersion('');
268 $this->drivererror[$module->id] = $module->error ? $module->error : '';
269 // If use an external lib
270 $this->liblabel[$module->id] = ($module->error ? '<span class="error">'.$module->error.'</span>' : $module->getLibLabel(''));
271 $this->libversion[$module->id] = $module->getLibVersion('');
272 }
273 }
274 }
275
276 return array_keys($this->driverlabel);
277 }
278
279
286 public function getPictoForKey($key)
287 {
288 return $this->picto[$key];
289 }
290
297 public function getDriverLabelForKey($key)
298 {
299 return $this->driverlabel[$key];
300 }
301
308 public function getDriverDescForKey($key)
309 {
310 return $this->driverdesc[$key];
311 }
312
319 public function getDriverVersionForKey($key)
320 {
321 return $this->driverversion[$key];
322 }
323
330 public function getLibLabelForKey($key)
331 {
332 return $this->liblabel[$key];
333 }
334
341 public function getLibVersionForKey($key)
342 {
343 return $this->libversion[$key];
344 }
345
352 public function getElementFromTableWithPrefix($tableNameWithPrefix)
353 {
354 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
355 $element = $tableElement;
356
357 if (isset(self::$mapTableToElement[$tableElement])) {
358 $element = self::$mapTableToElement[$tableElement];
359 }
360
361 return $element;
362 }
363}
Parent class for import file readers.
getLibVersionForKey($key)
Renvoi version de librairie externe du driver.
getDriverDescForKey($key)
Return description of import drivervoi la description d'un driver import.
getElementFromTableWithPrefix($tableNameWithPrefix)
Get element from table name with prefix.
getDriverLabelForKey($key)
Return label of driver import.
getLibLabel()
getDriverLabel
getDriverVersionForKey($key)
Renvoi version d'un driver import.
getDriverLabel()
getDriverLabel
getPictoForKey($key)
Return picto of import driver.
getDriverId()
getDriverId
getLibLabelForKey($key)
Renvoi libelle de librairie externe du driver.
getDriverVersion()
getDriverVersion
listOfAvailableImportFormat($db, $maxfilenamelength=0)
Load into memory list of available import format.
getDriverExtension()
getDriverExtension
getLibVersion()
getLibVersion
__construct()
Constructor.
getDriverDesc()
getDriverDesc
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
const MODULE_MAPPING
This mapping defines the conversion to the current internal names from the alternative allowed names ...