mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Merge branch 'develop' into patch-11
This commit is contained in:
commit
42280740aa
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
||||
/* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
// Load Dolibarr environment
|
||||
require '../../main.inc.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
|
||||
|
||||
|
|
@ -83,7 +85,25 @@ if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { // If
|
|||
/*
|
||||
* Actions
|
||||
*/
|
||||
if ($action == 'setdefault') {
|
||||
// Set a fiscal year as default
|
||||
$error = 0;
|
||||
|
||||
$defaultFiscalYear = GETPOSTINT('value');
|
||||
$defaultFiscalYearLabel = GETPOST('label', 'alpha');
|
||||
|
||||
if (!empty($defaultFiscalYear)) {
|
||||
dolibarr_set_const($db, 'ACCOUNTANCY_FISCALYEAR_DEFAULT', $defaultFiscalYear, 'chaine', 0, '', $conf->entity);
|
||||
} else {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
setEventMessages($langs->trans("FiscalYearSetAsDefault", $defaultFiscalYearLabel), null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans("Error"), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -148,6 +168,7 @@ if ($result) {
|
|||
print '<td>'.$langs->trans("DateEnd").'</td>';
|
||||
print '<td class="center">'.$langs->trans("NumberOfAccountancyEntries").'</td>';
|
||||
print '<td class="center">'.$langs->trans("NumberOfAccountancyMovements").'</td>';
|
||||
print '<td class="center">'.$langs->trans("Default").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Status").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
|
|
@ -160,6 +181,7 @@ if ($result) {
|
|||
|
||||
$fiscalyearstatic->ref = $obj->rowid;
|
||||
$fiscalyearstatic->id = $obj->rowid;
|
||||
$fiscalyearstatic->label = $obj->label;
|
||||
$fiscalyearstatic->date_start = $obj->date_start;
|
||||
$fiscalyearstatic->date_end = $obj->date_end;
|
||||
$fiscalyearstatic->statut = $obj->status;
|
||||
|
|
@ -174,12 +196,22 @@ if ($result) {
|
|||
print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>';
|
||||
print '<td class="center">'.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).'</td>';
|
||||
print '<td class="center">'.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).'</td>';
|
||||
|
||||
// Default
|
||||
print '<td class="center">';
|
||||
if (getDolGlobalString('ACCOUNTANCY_FISCALYEAR_DEFAULT') == (int) $fiscalyearstatic->ref) {
|
||||
print img_picto($langs->trans("Default"), 'on');
|
||||
} else {
|
||||
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdefault&token='.newToken().'&value='.urlencode($fiscalyearstatic->ref).'&label='.urlencode($fiscalyearstatic->label).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("SetAsDefault"), 'off').'</a>';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td class="right">'.$fiscalyearstatic->LibStatut($obj->status, 5).'</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
|
||||
print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/* Copyright (C) 2016 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2016 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2016-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2016-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
*
|
||||
|
|
@ -101,8 +101,13 @@ $formaccounting = new FormAccounting($db);
|
|||
$form = new Form($db);
|
||||
|
||||
if (empty($search_date_start) && !GETPOSTISSET('formfilteraction')) {
|
||||
$sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
$sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'";
|
||||
$sql = "SELECT date_start, date_end";
|
||||
$sql .=" FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
|
||||
$sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
|
||||
} else {
|
||||
$sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
|
||||
}
|
||||
$sql .= $db->plimit(1);
|
||||
$res = $db->query($sql);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
|
||||
* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
|
||||
|
|
@ -170,9 +170,15 @@ $form = new Form($db);
|
|||
|
||||
if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOSTINT('page') == '' && !GETPOSTINT('noreset') && $user->hasRight('accounting', 'mouvements', 'export')) {
|
||||
if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) {
|
||||
$query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
$query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
|
||||
$res = $db->query($query);
|
||||
$sql = "SELECT date_start, date_end";
|
||||
$sql .=" FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
|
||||
$sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
|
||||
} else {
|
||||
$sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
|
||||
}
|
||||
$sql .= $db->plimit(1);
|
||||
$res = $db->query($sql);
|
||||
|
||||
if ($db->num_rows($res) > 0) {
|
||||
$fiscalYear = $db->fetch_object($res);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inoveasya.solutions>
|
||||
* Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
|
||||
* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2022 Progiseize <a.bisotti@progiseiea-conseil.com>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
|
||||
* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2022 Progiseize <a.bisotti@progiseiea-conseil.com>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
|
||||
|
|
@ -149,14 +149,21 @@ if ($sortfield == "") {
|
|||
$object = new BookKeeping($db);
|
||||
$hookmanager->initHooks(array('bookkeepinglist'));
|
||||
|
||||
$formfiscalyear = new FormFiscalYear($db);
|
||||
$formaccounting = new FormAccounting($db);
|
||||
$form = new Form($db);
|
||||
|
||||
if (!in_array($action, array('delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOST('page', 'alpha') == '' && !GETPOSTINT('noreset') && $user->hasRight('accounting', 'mouvements', 'export')) {
|
||||
if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) {
|
||||
$query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
$query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
|
||||
$res = $db->query($query);
|
||||
$sql = "SELECT date_start, date_end";
|
||||
$sql .=" FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
|
||||
$sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
|
||||
} else {
|
||||
$sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
|
||||
}
|
||||
$sql .= $db->plimit(1);
|
||||
$res = $db->query($sql);
|
||||
|
||||
if ($db->num_rows($res) > 0) {
|
||||
$fiscalYear = $db->fetch_object($res);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
|
||||
* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2020 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
*
|
||||
|
|
@ -162,8 +162,13 @@ $formaccounting = new FormAccounting($db);
|
|||
$form = new Form($db);
|
||||
|
||||
if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('search_date_startday') && !GETPOSTISSET('search_date_startmonth') && !GETPOSTISSET('search_date_starthour')) {
|
||||
$sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
$sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
|
||||
$sql = "SELECT date_start, date_end";
|
||||
$sql .=" FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
|
||||
if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
|
||||
$sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
|
||||
} else {
|
||||
$sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
|
||||
}
|
||||
$sql .= $db->plimit(1);
|
||||
$res = $db->query($sql);
|
||||
|
||||
|
|
|
|||
112
htdocs/core/class/html.formfiscalyear.class.php
Normal file
112
htdocs/core/class/html.formfiscalyear.class.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/* Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.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
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/class/html.formfiscalyear.class.php
|
||||
* \ingroup Accountancy (Double entries)
|
||||
* \brief File of class with all html predefined components
|
||||
*/
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
|
||||
/**
|
||||
* Class to manage generation of HTML components for accounting management
|
||||
*/
|
||||
class FormFiscalYear extends Form
|
||||
{
|
||||
/**
|
||||
* @var DoliDB Database handler.
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* @var string Error code (or message)
|
||||
*/
|
||||
public $error = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of fiscal year
|
||||
*
|
||||
* @param int $selected Preselected type
|
||||
* @param string $htmlname Name of field in form
|
||||
* @param int $useempty Set to 1 if we want an empty value
|
||||
* @param int $maxlen Max length of text in combo box
|
||||
* @param int $help Add or not the admin help picto
|
||||
* @return void|string HTML component with the select
|
||||
*/
|
||||
public function selectFiscalYear($selected = 0, $htmlname = 'fiscalyear', $useempty = 0, $maxlen = 0, $help = 1)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$out = '';
|
||||
|
||||
$sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status";
|
||||
$sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear as f";
|
||||
$sql .= " WHERE f.entity = ".$conf->entity;
|
||||
$sql .= " ORDER BY f.date_start ASC";
|
||||
|
||||
dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
$out .= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'">';
|
||||
$i = 0;
|
||||
|
||||
if ($useempty) {
|
||||
$out .= '<option value="0"> </option>';
|
||||
}
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$titletoshowhtml = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$obj->date_start . " - " . $obj->date_end.')</span>';
|
||||
$titletoshow = ($maxlen ? dol_trunc($obj->label, $maxlen) : $obj->label).' <span class="opacitymedium">('.$langs->transnoentitiesnoconv("FiscalYearFromTo", $obj->date_start, $obj->date_end).')</span>';
|
||||
|
||||
$out .= '<option value="'.$obj->rowid.'"';
|
||||
if ($obj->rowid == $selected) {
|
||||
$out .= ' selected';
|
||||
}
|
||||
//$out .= ' data-html="'.dol_escape_htmltag(dol_string_onlythesehtmltags($titletoshowhtml, 1, 0, 0, 0, array('span'))).'"';
|
||||
$out .= ' data-html="'.dolPrintHTMLForAttribute($titletoshowhtml).'"';
|
||||
$out .= '>';
|
||||
$out .= dol_escape_htmltag($titletoshow);
|
||||
$out .= '</option>';
|
||||
$i++;
|
||||
}
|
||||
$out .= '</select>';
|
||||
//if ($user->admin && $help) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||
|
||||
$out .= ajax_combobox($htmlname, array());
|
||||
} else {
|
||||
$out .= '<span class="opacitymedium">'.$langs->trans("ErrorNoFiscalyearDefined", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Fiscalyear")).'</span>';
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
|
@ -283,6 +283,9 @@ ImportDataset_tax_contrib=Social/fiscal taxes
|
|||
ImportDataset_tax_vat=VAT payments
|
||||
ErrorBankAccountNotFound=Error: Bank account not found
|
||||
FiscalPeriod=Accounting period
|
||||
ErrorNoFiscalyearDefined=Error, no fiscal year defined (See %s - %s - %s)
|
||||
FiscalYearSetAsDefault=Fiscal year (%s) defined as default
|
||||
FiscalYearFromTo=Period from %s to %s
|
||||
FiscalYearOpened=Fiscal year opened
|
||||
FiscalYearClosed=Fiscal year closed
|
||||
FiscalYearOpenedShort=Opened
|
||||
|
|
|
|||
316
htdocs/modulebuilder/template/build/buildzip.php
Normal file
316
htdocs/modulebuilder/template/build/buildzip.php
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
#!/usr/bin/env php -d memory_limit=256M
|
||||
<?php
|
||||
/**
|
||||
* buildzip.php
|
||||
*
|
||||
* Copyright (c) 2023-2025 Eric Seigne <eric.seigne@cap-rel.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
The goal of that php CLI script is to make zip package of your module
|
||||
as an alternative to web "build zip" or "perl script makepack"
|
||||
*/
|
||||
|
||||
// ============================================= configuration
|
||||
|
||||
/**
|
||||
* list of files & dirs of your module
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
$listOfModuleContent = [
|
||||
'admin',
|
||||
'ajax',
|
||||
'backport',
|
||||
'class',
|
||||
'css',
|
||||
'COPYING',
|
||||
'core',
|
||||
'img',
|
||||
'js',
|
||||
'langs',
|
||||
'lib',
|
||||
'sql',
|
||||
'tpl',
|
||||
'*.md',
|
||||
'*.json',
|
||||
'*.php',
|
||||
'modulebuilder.txt',
|
||||
];
|
||||
|
||||
/**
|
||||
* if you want to exclude some files from your zip
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
$exclude_list = [
|
||||
'/^.git$/',
|
||||
'/.*js.map/',
|
||||
'/DEV.md/'
|
||||
];
|
||||
|
||||
// ============================================= end of configuration
|
||||
|
||||
/**
|
||||
* auto detect module name and version from file name
|
||||
*
|
||||
* @return (string|string)[] module name and module version
|
||||
*/
|
||||
function detectModule()
|
||||
{
|
||||
$name = $version = "";
|
||||
$tab = glob("core/modules/mod*.class.php");
|
||||
if (count($tab) == 0) {
|
||||
echo "[fail] Error on auto detect data : there is no mod*.class.php file into core/modules dir\n";
|
||||
exit(-1);
|
||||
}
|
||||
if (count($tab) == 1) {
|
||||
$file = $tab[0];
|
||||
$pattern = "/.*mod(?<mod>.*)\.class\.php/";
|
||||
if (preg_match_all($pattern, $file, $matches)) {
|
||||
$name = strtolower(reset($matches['mod']));
|
||||
}
|
||||
|
||||
echo "extract data from $file\n";
|
||||
if (!file_exists($file) || $name == "") {
|
||||
echo "[fail] Error on auto detect data\n";
|
||||
exit(-2);
|
||||
}
|
||||
} else {
|
||||
echo "[fail] Error there is more than one mod*.class.php file into core/modules dir\n";
|
||||
exit(-3);
|
||||
}
|
||||
|
||||
//extract version from file
|
||||
$contents = file_get_contents($file);
|
||||
$pattern = "/^.*this->version\s*=\s*'(?<version>.*)'\s*;.*\$/m";
|
||||
|
||||
// search, and store all matching occurrences in $matches
|
||||
if (preg_match_all($pattern, $contents, $matches)) {
|
||||
$version = reset($matches['version']);
|
||||
}
|
||||
|
||||
if (version_compare($version, '0.0.1', '>=') != 1) {
|
||||
echo "[fail] Error auto extract version fail\n";
|
||||
exit(-4);
|
||||
}
|
||||
|
||||
echo "module name = $name, version = $version\n";
|
||||
return [(string) $name, (string) $version];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete recursively a directory
|
||||
*
|
||||
* @param string $dir dir path to delete
|
||||
*
|
||||
* @return bool true on success or false on failure.
|
||||
*/
|
||||
function delTree($dir)
|
||||
{
|
||||
$files = array_diff(scandir($dir), array('.', '..'));
|
||||
foreach ($files as $file) {
|
||||
(is_dir("$dir/$file")) ? delTree("$dir/$file") : secureUnlink("$dir/$file");
|
||||
}
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* do a secure delete file/dir with double check
|
||||
* (don't trust unlink return)
|
||||
*
|
||||
* @param string $path full path to delete
|
||||
*
|
||||
* @return bool true on success ($path does not exists at the end of process), else exit
|
||||
*/
|
||||
function secureUnlink($path)
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
if (unlink($path)) {
|
||||
//then check if really deleted
|
||||
clearstatcache();
|
||||
if (file_exists($path)) { // @phpstan-ignore-line
|
||||
echo "[fail] unlink of $path fail !\n";
|
||||
exit(-5);
|
||||
}
|
||||
} else {
|
||||
echo "[fail] unlink of $path fail !\n";
|
||||
exit(-6);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a directory and check if dir exists
|
||||
*
|
||||
* @param string $path path to make
|
||||
*
|
||||
* @return bool true on success ($path exists at the end of process), else exit
|
||||
*/
|
||||
function mkdirAndCheck($path)
|
||||
{
|
||||
if (mkdir($path)) {
|
||||
clearstatcache();
|
||||
if (is_dir($path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
echo "[fail] Error on $path (mkdir)\n";
|
||||
exit(7);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if that filename is concerned by exclude filter
|
||||
*
|
||||
* @param string $filename file name to check
|
||||
*
|
||||
* @return bool true if file is in excluded list
|
||||
*/
|
||||
function is_excluded($filename)
|
||||
{
|
||||
global $exclude_list;
|
||||
$count = 0;
|
||||
$notused = preg_filter($exclude_list, '1', $filename, -1, $count);
|
||||
if ($count > 0) {
|
||||
echo " - exclude $filename\n";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* recursive copy files & dirs
|
||||
*
|
||||
* @param string $src source dir
|
||||
* @param string $dst target dir
|
||||
*
|
||||
* @return bool true on success or false on failure.
|
||||
*/
|
||||
function rcopy($src, $dst)
|
||||
{
|
||||
if (is_dir($src)) {
|
||||
// Make the destination directory if not exist
|
||||
mkdirAndCheck($dst);
|
||||
// open the source directory
|
||||
$dir = opendir($src);
|
||||
|
||||
// Loop through the files in source directory
|
||||
while ($file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
// Recursively calling custom copy function
|
||||
// for sub directory
|
||||
if (!rcopy($src . '/' . $file, $dst . '/' . $file)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!is_excluded($file)) {
|
||||
if (!copy($src . '/' . $file, $dst . '/' . $file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
} elseif (is_file($src)) {
|
||||
if (!is_excluded($src)) {
|
||||
if (!copy($src, $dst)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* build a zip file with only php code and no external depends
|
||||
* on "zip" exec for example
|
||||
*
|
||||
* @param string $folder folder to use as zip root
|
||||
* @param ZipArchive $zip zip object (ZipArchive)
|
||||
* @param string $root relative root path into the zip
|
||||
*
|
||||
* @return bool true on success or false on failure.
|
||||
*/
|
||||
function zipDir($folder, &$zip, $root = "")
|
||||
{
|
||||
foreach (new \DirectoryIterator($folder) as $f) {
|
||||
if ($f->isDot()) {
|
||||
continue;
|
||||
} //skip . ..
|
||||
$src = $folder . '/' . $f;
|
||||
$dst = substr($f->getPathname(), strlen($root));
|
||||
if ($f->isDir()) {
|
||||
if ($zip->addEmptyDir($dst)) {
|
||||
if (zipDir($src, $zip, $root)) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($f->isFile()) {
|
||||
if (! $zip->addFile($src, $dst)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* main part of script
|
||||
*/
|
||||
|
||||
list($mod, $version) = detectModule();
|
||||
$outzip = sys_get_temp_dir() . "/module_" . $mod . "-" . $version . ".zip";
|
||||
if (file_exists($outzip)) {
|
||||
secureUnlink($outzip);
|
||||
}
|
||||
|
||||
//copy all sources into system temp directory
|
||||
$tmpdir = tempnam(sys_get_temp_dir(), $mod . "-module");
|
||||
secureUnlink($tmpdir);
|
||||
mkdirAndCheck($tmpdir);
|
||||
$dst = $tmpdir . "/" . $mod;
|
||||
mkdirAndCheck($dst);
|
||||
|
||||
foreach ($listOfModuleContent as $moduleContent) {
|
||||
foreach (glob($moduleContent) as $entry) {
|
||||
if (!rcopy($entry, $dst . '/' . $entry)) {
|
||||
echo "[fail] Error on copy " . $entry . " to " . $dst . "/" . $entry . "\n";
|
||||
echo "Please take time to analyze the problem and fix the bug\n";
|
||||
exit(-8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$z = new ZipArchive();
|
||||
$z->open($outzip, ZIPARCHIVE::CREATE);
|
||||
zipDir($tmpdir, $z, $tmpdir . '/');
|
||||
$z->close();
|
||||
delTree($tmpdir);
|
||||
if (file_exists($outzip)) {
|
||||
echo "[success] module archive is ready : $outzip ...\n";
|
||||
} else {
|
||||
echo "[fail] build zip error\n";
|
||||
exit(-9);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user