Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
7ba424a467
@ -482,6 +482,16 @@ function deletePerms($file)
|
||||
dolReplaceInFile($file, array($allContent => ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two value
|
||||
* @param int|string $a value 1
|
||||
* @param int|string $b value 2
|
||||
* @return int less 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
|
||||
*/
|
||||
function compareFirstValue($a, $b)
|
||||
{
|
||||
return strcmp($a[0], $b[0]);
|
||||
}
|
||||
/**
|
||||
* Rewriting all permissions after any actions
|
||||
* @param string $file filename or path
|
||||
@ -515,11 +525,46 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $action)
|
||||
$permissions[$i][4] = "\$this->rights[\$r][4] = '".$permissions[$i][4]."'";
|
||||
$permissions[$i][5] = "\$this->rights[\$r][5] = '".$permissions[$i][5]."';\n\t\t";
|
||||
}
|
||||
// for group permissions by object
|
||||
$perms_grouped = array();
|
||||
foreach ($permissions as $perms) {
|
||||
$object = $perms[4];
|
||||
if (!isset($perms_grouped[$object])) {
|
||||
$perms_grouped[$object] = [];
|
||||
}
|
||||
$perms_grouped[$object][] = $perms;
|
||||
}
|
||||
//$perms_grouped = array_values($perms_grouped);
|
||||
$permissions = $perms_grouped;
|
||||
|
||||
|
||||
// parcourir les objets
|
||||
$o=0;
|
||||
foreach ($permissions as &$object) {
|
||||
// récupérer la permission de l'objet
|
||||
$p = 1;
|
||||
foreach ($object as &$obj) {
|
||||
if (str_contains($obj[5], 'read')) {
|
||||
$obj[0] = "\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o." * 10) + 0 + 1)";
|
||||
} elseif (str_contains($obj[5], 'write')) {
|
||||
$obj[0] = "\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o." * 10) + 1 + 1)";
|
||||
} elseif (str_contains($obj[5], 'delete')) {
|
||||
$obj[0] = "\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o." * 10) + 2 + 1)";
|
||||
} else {
|
||||
$obj[0] = "\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o." * 10) + ".$p." + 1)";
|
||||
$p++;
|
||||
}
|
||||
}
|
||||
usort($object, 'compareFirstValue');
|
||||
$o++;
|
||||
}
|
||||
|
||||
//convert to string
|
||||
foreach ($permissions as $perms) {
|
||||
$rights[] = implode(";\n\t\t", $perms);
|
||||
$rights[] = "\$r++;\n\t\t";
|
||||
foreach ($perms as $per) {
|
||||
$rights[] = implode(";\n\t\t", $per);
|
||||
$rights[] = "\$r++;\n\t\t";
|
||||
}
|
||||
}
|
||||
$rights_str = implode("", $rights);
|
||||
// delete all permission from file
|
||||
@ -527,6 +572,8 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $action)
|
||||
// rewrite all permission again
|
||||
dolReplaceInFile($file, array('/* BEGIN MODULEBUILDER PERMISSIONS */' => '/* BEGIN MODULEBUILDER PERMISSIONS */'."\n\t\t".$rights_str));
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,6 +660,7 @@ function writePropsInAsciiDoc($file, $objectname, $destfile)
|
||||
}
|
||||
// end table
|
||||
$table .= "|===";
|
||||
$table .= "__ end table for object $objectname";
|
||||
//write in file
|
||||
$writeInFile = dolReplaceInFile($destfile, array('== DATA SPECIFICATIONS'=> $table));
|
||||
if ($writeInFile<0) {
|
||||
@ -621,6 +669,23 @@ function writePropsInAsciiDoc($file, $objectname, $destfile)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete property from documentation if we delete object
|
||||
* @param string $file file or path
|
||||
* @param string $objectname name of object wants to deleted
|
||||
* @return void
|
||||
*/
|
||||
function deletePropsFromDoc($file, $objectname)
|
||||
{
|
||||
|
||||
$start = "== Table of fields and their properties for object *".ucfirst($objectname)."* : ";
|
||||
$end = "__ end table for object ".ucfirst($objectname);
|
||||
$str = file_get_contents($file);
|
||||
$search = '/' . preg_quote($start, '/') . '(.*?)' . preg_quote($end, '/') . '/s';
|
||||
$new_contents = preg_replace($search, '', $str);
|
||||
file_put_contents($file, $new_contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a string and return all lines needed from file
|
||||
* @param string $file file for searching
|
||||
|
||||
@ -1542,6 +1542,13 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
||||
setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
// check if documentation was generate and add table of properties object
|
||||
$file = $destdir.'/class/'.strtolower($objectname).'.class.php';
|
||||
$destfile = $destdir.'/doc/Documentation.asciidoc';
|
||||
|
||||
if (file_exists($destfile)) {
|
||||
writePropsInAsciiDoc($file, $objectname, $destfile);
|
||||
}
|
||||
}
|
||||
if (!$error) {
|
||||
// Edit sql with new properties
|
||||
@ -1870,6 +1877,12 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
|
||||
'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
|
||||
);
|
||||
|
||||
// delete property if documentation was generated
|
||||
$file_doc = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
|
||||
if (file_exists($file_doc)) {
|
||||
deletePropsFromDoc($file_doc, $objectname);
|
||||
}
|
||||
|
||||
//menu for the object selected
|
||||
// load class and check if menu exist for this object
|
||||
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
||||
@ -4779,7 +4792,7 @@ if ($module == 'initmodule') {
|
||||
|
||||
//form for add new right
|
||||
print '<tr class="small">';
|
||||
print '<td><input type="text" readonly name="id" class="width75" value="'.dol_escape_htmltag($moduleobj->numero.sprintf('%02d', $i + count($perms))).'"></td>';
|
||||
print '<td><input type="text" readonly name="id" class="width75" value="0"></td>';
|
||||
print '<td>';
|
||||
print '<select name="label" >';
|
||||
print '<option value=""></option>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user