dolibarr 21.0.0-beta
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
43 public $datatoimport;
44
48 public $error = '';
49
53 public $errors = array();
54
58 public $warnings = array();
59
63 public $id;
64
68 public $label;
69
73 public $extension;
74
79 public $version = 'dolibarr';
80
85 public $phpmin = array(7, 0);
86
91 public $label_lib;
92
97 public $version_lib;
98
99 // Array of all drivers
103 public $driverlabel = array();
104
108 public $driverdesc = array();
109
113 public $driverversion = array();
114
118 public $drivererror = array();
119
123 public $liblabel = array();
124
128 public $libversion = array();
129
133 public $charset;
134
138 public $picto;
139
143 public $desc;
144
148 public $escape;
149
153 public $enclosure;
154
158 public $thirdpartyobject;
159
163 public static $mapTableToElement = MODULE_MAPPING;
164
168 public function __construct()
169 {
170 global $hookmanager;
171
172 if (is_object($hookmanager)) {
173 $hookmanager->initHooks(array('import'));
174 $parameters = array();
175 $reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
176 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
177 foreach ($hookmanager->resArray as $mapList) {
178 self::$mapTableToElement[$mapList['table']] = $mapList['element'];
179 }
180 }
181 }
182 }
183
189 public function getDriverId()
190 {
191 return $this->id;
192 }
193
199 public function getDriverLabel()
200 {
201 return $this->label;
202 }
203
209 public function getDriverDesc()
210 {
211 return $this->desc;
212 }
213
219 public function getDriverExtension()
220 {
221 return $this->extension;
222 }
223
229 public function getDriverVersion()
230 {
231 return $this->version;
232 }
233
239 public function getLibLabel()
240 {
241 return $this->label_lib;
242 }
243
249 public function getLibVersion()
250 {
251 return $this->version_lib;
252 }
253
254
262 public function listOfAvailableImportFormat($db, $maxfilenamelength = 0)
263 {
264 dol_syslog(get_class($this)."::listOfAvailableImportFormat");
265
266 $dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
267 $handle = opendir($dir);
268
269 // Search list ov drivers available and qualified
270 if (is_resource($handle)) {
271 while (($file = readdir($handle)) !== false) {
272 $reg = array();
273 if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) {
274 $moduleid = $reg[1];
275
276 // Loading Class
277 $file = $dir."/import_".$moduleid.".modules.php";
278 $classname = "Import".ucfirst($moduleid);
279
280 require_once $file;
281 $module = new $classname($db, '');
282 '@phan-var-force ModeleImports $module';
283
284 // Picto
285 $this->picto[$module->id] = $module->picto;
286 // Driver properties
287 $this->driverlabel[$module->id] = $module->getDriverLabel();
288 $this->driverdesc[$module->id] = $module->getDriverDesc();
289 $this->driverversion[$module->id] = $module->getDriverVersion();
290 $this->drivererror[$module->id] = $module->error ? $module->error : '';
291 // If use an external lib
292 $this->liblabel[$module->id] = ($module->error ? '<span class="error">'.$module->error.'</span>' : $module->getLibLabel());
293 $this->libversion[$module->id] = $module->getLibVersion();
294 }
295 }
296 }
297
298 return array_keys($this->driverlabel);
299 }
300
301
308 public function getPictoForKey($key)
309 {
310 return $this->picto[$key];
311 }
312
319 public function getDriverLabelForKey($key)
320 {
321 return $this->driverlabel[$key];
322 }
323
330 public function getDriverDescForKey($key)
331 {
332 return $this->driverdesc[$key];
333 }
334
341 public function getDriverVersionForKey($key)
342 {
343 return $this->driverversion[$key];
344 }
345
352 public function getLibLabelForKey($key)
353 {
354 return $this->liblabel[$key];
355 }
356
363 public function getLibVersionForKey($key)
364 {
365 return $this->libversion[$key];
366 }
367
374 public function getElementFromTableWithPrefix($tableNameWithPrefix)
375 {
376 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
377 $element = $tableElement;
378
379 if (isset(self::$mapTableToElement[$tableElement])) {
380 $element = self::$mapTableToElement[$tableElement];
381 }
382
383 return $element;
384 }
385
386 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
393 public function import_open_file($file)
394 {
395 // phpcs:enable
396 $msg = get_class($this)."::".__FUNCTION__." not implemented";
397 dol_syslog($msg, LOG_ERR);
398 $this->errors[] = $msg;
399 $this->error = $msg;
400 return -1;
401 }
402
403
404 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
411 public function import_get_nb_of_lines($file)
412 {
413 // phpcs:enable
414 $msg = get_class($this)."::".__FUNCTION__." not implemented";
415 dol_syslog($msg, LOG_ERR);
416 $this->errors[] = $msg;
417 $this->error = $msg;
418 return -1;
419 }
420
421 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
427 public function import_read_header()
428 {
429 // phpcs:enable
430 $msg = get_class($this)."::".__FUNCTION__." not implemented";
431 dol_syslog($msg, LOG_ERR);
432 $this->errors[] = $msg;
433 $this->error = $msg;
434 return -1;
435 }
436
437
438 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
444 public function import_read_record()
445 {
446 // phpcs:enable
447 $msg = get_class($this)."::".__FUNCTION__." not implemented";
448 dol_syslog($msg, LOG_ERR);
449 $this->errors[] = $msg;
450 $this->error = $msg;
451 return array();
452 }
453
454
455 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
461 public function import_close_file()
462 {
463 // phpcs:enable
464 $msg = get_class($this)."::".__FUNCTION__." not implemented";
465 dol_syslog($msg, LOG_ERR);
466 $this->errors[] = $msg;
467 $this->error = $msg;
468 return -1;
469 }
470
471
472 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
484 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
485 {
486 // phpcs:enable
487 $msg = get_class($this)."::".__FUNCTION__." not implemented";
488 dol_syslog($msg, LOG_ERR);
489 $this->errors[] = $msg;
490 $this->error = $msg;
491 return -1;
492 }
493}
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.
import_get_nb_of_lines($file)
Return nb of records.
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.
import_read_record()
Return array of next record in input file.
import_open_file($file)
Open input file.
import_read_header()
Input header line from file.
getDriverVersion()
getDriverVersion
listOfAvailableImportFormat($db, $maxfilenamelength=0)
Load into memory list of available import format.
getDriverExtension()
getDriverExtension
getLibVersion()
getLibVersion
__construct()
Constructor.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
getDriverDesc()
getDriverDesc
import_close_file()
Close file handle.
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 ...