dolibarr 21.0.0-alpha
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
283 // Picto
284 $this->picto[$module->id] = $module->picto;
285 // Driver properties
286 $this->driverlabel[$module->id] = $module->getDriverLabel('');
287 $this->driverdesc[$module->id] = $module->getDriverDesc('');
288 $this->driverversion[$module->id] = $module->getDriverVersion('');
289 $this->drivererror[$module->id] = $module->error ? $module->error : '';
290 // If use an external lib
291 $this->liblabel[$module->id] = ($module->error ? '<span class="error">'.$module->error.'</span>' : $module->getLibLabel(''));
292 $this->libversion[$module->id] = $module->getLibVersion('');
293 }
294 }
295 }
296
297 return array_keys($this->driverlabel);
298 }
299
300
307 public function getPictoForKey($key)
308 {
309 return $this->picto[$key];
310 }
311
318 public function getDriverLabelForKey($key)
319 {
320 return $this->driverlabel[$key];
321 }
322
329 public function getDriverDescForKey($key)
330 {
331 return $this->driverdesc[$key];
332 }
333
340 public function getDriverVersionForKey($key)
341 {
342 return $this->driverversion[$key];
343 }
344
351 public function getLibLabelForKey($key)
352 {
353 return $this->liblabel[$key];
354 }
355
362 public function getLibVersionForKey($key)
363 {
364 return $this->libversion[$key];
365 }
366
373 public function getElementFromTableWithPrefix($tableNameWithPrefix)
374 {
375 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
376 $element = $tableElement;
377
378 if (isset(self::$mapTableToElement[$tableElement])) {
379 $element = self::$mapTableToElement[$tableElement];
380 }
381
382 return $element;
383 }
384
385 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
392 public function import_open_file($file)
393 {
394 // phpcs:enable
395 $msg = get_class($this)."::".__FUNCTION__." not implemented";
396 dol_syslog($msg, LOG_ERR);
397 $this->errors[] = $msg;
398 $this->error = $msg;
399 return -1;
400 }
401
402
403 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
410 public function import_get_nb_of_lines($file)
411 {
412 // phpcs:enable
413 $msg = get_class($this)."::".__FUNCTION__." not implemented";
414 dol_syslog($msg, LOG_ERR);
415 $this->errors[] = $msg;
416 $this->error = $msg;
417 return -1;
418 }
419
420 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
426 public function import_read_header()
427 {
428 // phpcs:enable
429 $msg = get_class($this)."::".__FUNCTION__." not implemented";
430 dol_syslog($msg, LOG_ERR);
431 $this->errors[] = $msg;
432 $this->error = $msg;
433 return -1;
434 }
435
436
437 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
443 public function import_read_record()
444 {
445 // phpcs:enable
446 $msg = get_class($this)."::".__FUNCTION__." not implemented";
447 dol_syslog($msg, LOG_ERR);
448 $this->errors[] = $msg;
449 $this->error = $msg;
450 return array();
451 }
452
453
454 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
460 public function import_close_file()
461 {
462 // phpcs:enable
463 $msg = get_class($this)."::".__FUNCTION__." not implemented";
464 dol_syslog($msg, LOG_ERR);
465 $this->errors[] = $msg;
466 $this->error = $msg;
467 return -1;
468 }
469
470
471 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
483 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
484 {
485 // phpcs:enable
486 $msg = get_class($this)."::".__FUNCTION__." not implemented";
487 dol_syslog($msg, LOG_ERR);
488 $this->errors[] = $msg;
489 $this->error = $msg;
490 return -1;
491 }
492}
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 ...