Skip to content

Commit

Permalink
The yaml file is changed to a json so as not to depend on additional …
Browse files Browse the repository at this point in the history
…libraries.
  • Loading branch information
rsanjoseo committed Apr 1, 2024
1 parent 87e757d commit fda8382
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 54 deletions.
26 changes: 18 additions & 8 deletions Deprecated/Core/Lib/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static function createClassPaths($searchPath = '/../Deprecated/Modules',
}

/**
* Same as createClassPaths, but trying to use a yaml file cache.
* Same as createClassPaths, but trying to use a file cache.
*
* @param $searchPath
* @param $folderName
Expand All @@ -76,25 +76,35 @@ public static function getClassPaths($searchPath = '/../Deprecated/Modules', $fo
// Failed to create directory for cache
return static::createClassPaths();
}
if (!function_exists('yaml_parse')) {
return static::createClassPaths();
}
$file = $path . '/classpaths.yaml';
$file = $path . '/classpaths.json';
if (file_exists($file)) {
return yaml_parse_file($file);
return json_decode(file_get_contents($file), true);
}
$data = static::createClassPaths();
file_put_contents($file, yaml_parse($data));
file_put_contents($file, json_encode($data));
return $data;
}

public static function loadClass($name, $param)
/**
* Loads a model class given the name and an alternative parameter to be passed to
* the model during creation (usually a db instance is passed to it).
*
* @param $name
* @param $param
*
* @return mixed|null
*/
public static function loadModel($name, $param = null)
{
$classes = static::getClassPaths();
if (!isset($classes[$name])) {
return null;
}

if ($param === null) {
return new $classes[$name]();
}

return new $classes[$name]($param);
}
}
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"vendor-dir": "vendor",
"process-timeout": 0,
"platform": {
"php": "8.2"
"php": "8.1"
}
},
"require": {
"php": ">=8.2.0",
"php": ">=8.1.0",
"ckeditor/ckeditor": "4.12.1",
"mike42/escpos-php": "^4.0",
"mobiledetect/mobiledetectlib": "2.8.41",
Expand All @@ -50,8 +50,7 @@
"globalcitizen/php-iban": "^4.2",
"jenssegers/blade": "^1.4",
"symfony/yaml": "^5.4",
"illuminate/database": "^8.83",
"ext-yaml": "*"
"illuminate/database": "^8.83"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
Expand Down
5 changes: 3 additions & 2 deletions htdocs/bom/bom_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/* Copyright (C) 2017-2023 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -270,7 +271,7 @@
}
}

$bomline = new BOMLine($db);
$bomline = new BomLine($db);
$bomline->fetch($lineid);

$fk_default_workstation = $bomline->fk_default_workstation;
Expand Down
10 changes: 5 additions & 5 deletions htdocs/bom/class/bom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class BOM extends GenericDocument
/**
* @var string Name of subtable class that manage subtable lines
*/
public $class_element_line = 'BOMLine';
public $class_element_line = 'BomLine';

// /**
// * @var array List of child tables. To test if we can delete object.
Expand Down Expand Up @@ -648,7 +648,7 @@ public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_chang
}

// Insert line
$line = new BOMLine($this->db);
$line = new BomLine($this->db);

$line->context = $this->context;

Expand Down Expand Up @@ -739,7 +739,7 @@ public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change
$this->db->begin();

//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new BOMLine($this->db);
$line = new BomLine($this->db);
$line->fetch($rowid);
$line->fetch_optionals();

Expand Down Expand Up @@ -823,7 +823,7 @@ public function deleteLine(User $user, $idline, $notrigger = 0)
$this->db->begin();

//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new BOMLine($this->db);
$line = new BomLine($this->db);
$line->fetch($idline);
$line->fetch_optionals();

Expand Down Expand Up @@ -1276,7 +1276,7 @@ public function getLinesArray()
{
$this->lines = array();

$objectline = new BOMLine($this->db);
$objectline = new BomLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_bom:=:' . ((int) $this->id) . ')');

if (is_numeric($result)) {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/bom/class/bomline.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Class for BOMLine
*/
class BOMLine extends GenericDocumentLine
class BomLine extends GenericDocumentLine
{
/**
* @var string ID to identify managed object
Expand Down
19 changes: 10 additions & 9 deletions htdocs/bom/tpl/objectline_create.tpl.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -60,7 +61,7 @@
//print $object->element;

// Lines for extrafield
$objectline = new BOMLine($this->db);
$objectline = new BomLine($this->db);

print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";

Expand Down
15 changes: 8 additions & 7 deletions htdocs/bom/tpl/objectline_edit.tpl.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -60,7 +61,7 @@
$colspan = 3; // Columns: total ht + col edit + col delete

// Lines for extrafield
$objectline = new BOMLine($this->db);
$objectline = new BomLine($this->db);

print "<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->\n";

Expand Down
19 changes: 10 additions & 9 deletions htdocs/bom/tpl/objectline_view.tpl.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/* Copyright (C) 2010-2013 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2010-2013 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -84,7 +85,7 @@
$domData .= ' data-product_type="' . $line->product_type . '"';

// Lines for extrafield
$objectline = new BOMLine($object->db);
$objectline = new BomLine($object->db);

$coldisplay = 0;
print "<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
Expand Down Expand Up @@ -264,7 +265,7 @@
$sub_bom->fetch($obj->fk_bom_child);
}

$sub_bom_line = new BOMLine($object->db);
$sub_bom_line = new BomLine($object->db);
$sub_bom_line->fetch($obj->rowid);

//If hidden conf is set, we show directly all the sub-BOM lines
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/boxes/box_dolibarr_state_board.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function loadBox($max = 5)
}

if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) {
$board = Misc::loadClass($class, $this->db);
$board = Misc::loadModel($class, $this->db);

if (empty($board)) {
include_once $includes[$val]; // Loading a class cost around 1Mb
Expand Down
1 change: 1 addition & 0 deletions htdocs/core/commonfieldsinexport.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
}
}
} else {
dump([$keyforclass]);
dol_print_error($this->db, 'Failed to find class ' . $keyforclass . ', even after the include of ' . $keyforclassfile);
}
// End add common fields
2 changes: 1 addition & 1 deletion htdocs/core/modules/modBom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function __construct($db)
$keyforclassfile = '/bom/class/bom.class.php';
$keyforelement = 'bom';
include DOL_DOCUMENT_ROOT . '/core/commonfieldsinexport.inc.php';
$keyforclass = 'BOMLine';
$keyforclass = 'BomLine';
$keyforclassfile = '/bom/class/bom.class.php'; // @phan-suppress-current-line PhanPluginRedundantAssignment
$keyforelement = 'bomline';
$keyforalias = 'tl';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/exports/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
'contract_line' => 'ContractLine',
'translation' => 'Translation',
'bom' => 'BOM',
'bomline' => 'BOMLine',
'bomline' => 'BomLine',
'conferenceorboothattendee' => 'Attendee'
);

Expand Down
2 changes: 1 addition & 1 deletion htdocs/imports/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
'contract_line' => 'ContractLine',
'translation' => 'Translation',
'bom' => 'BOM',
'bomline' => 'BOMLine'
'bomline' => 'BomLine'
);

$datatoimport = GETPOST('datatoimport');
Expand Down
5 changes: 3 additions & 2 deletions htdocs/mrp/mo_card.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -151,7 +152,7 @@
$mo_parent = $object;

$moline = new MoLine($db);
$objectbomchildline = new BOMLine($db);
$objectbomchildline = new BomLine($db);

foreach ($TBomLineId as $id_bom_line) {
$object = new Mo($db); // modified by the actions_addupdatedelete.inc.php
Expand Down
7 changes: 4 additions & 3 deletions htdocs/mrp/tpl/originproductline.tpl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* 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
Expand Down Expand Up @@ -123,7 +124,7 @@
$sub_bom = new BOM($db);
$sub_bom->fetch($obj->fk_bom_child);

$sub_bom_line = new BOMLine($db);
$sub_bom_line = new BomLine($db);
$sub_bom_line->fetch($obj->rowid);

//If hidden conf is set, we show directly all the sub-BOM lines
Expand Down

0 comments on commit fda8382

Please sign in to comment.