From 742890157a1d252fdcece194ecd112c750cbf194 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Mon, 20 Mar 2023 19:43:23 +0100 Subject: [PATCH 1/4] delete table of property from documentation --- htdocs/core/lib/modulebuilder.lib.php | 45 +++++++++++++++++++++++++++ htdocs/modulebuilder/index.php | 6 ++++ 2 files changed, 51 insertions(+) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 26b5437aacc..200d2e98bda 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -620,3 +620,48 @@ function writePropsInAsciiDoc($file, $objectname, $destfile) } return 1; } + +/** + * Search a string and return all lines needed from file + * @param string $file file for searching + * @param string $start start line if exist + * @param string $end end line if exist + * @return string return the content needed + */ +function getFromFile($file, $start, $end) +{ + $i = 1; + $keys = array(); + $lines = file($file); + // Search for start and end lines + foreach ($lines as $i => $line) { + if (strpos($line, $start) !== false) { + // Copy lines until the end on array + while (($line = $lines[++$i]) !== false) { + if (strpos($line, $end) !== false) { + break; + } + $keys[] = $line; + } + break; + } + } + $content = implode("", $keys); + return $content; +} + +/** + * 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); + $string = getFromFile($file, $start, $end); + dolReplaceInFile($file, array($string => '')); + dolReplaceInFile($file, array($start => '', $end => '')); +} diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index c0c29ea2864..82542691f2c 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1914,6 +1914,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']; From 55667c5ac4b7022d405c38c84733ccea3938052c Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Tue, 21 Mar 2023 12:57:02 +0100 Subject: [PATCH 2/4] update function for delete properties from Doc --- htdocs/core/lib/modulebuilder.lib.php | 36 +++------------------------ 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 200d2e98bda..5b5de104d3d 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -621,35 +621,6 @@ function writePropsInAsciiDoc($file, $objectname, $destfile) return 1; } -/** - * Search a string and return all lines needed from file - * @param string $file file for searching - * @param string $start start line if exist - * @param string $end end line if exist - * @return string return the content needed - */ -function getFromFile($file, $start, $end) -{ - $i = 1; - $keys = array(); - $lines = file($file); - // Search for start and end lines - foreach ($lines as $i => $line) { - if (strpos($line, $start) !== false) { - // Copy lines until the end on array - while (($line = $lines[++$i]) !== false) { - if (strpos($line, $end) !== false) { - break; - } - $keys[] = $line; - } - break; - } - } - $content = implode("", $keys); - return $content; -} - /** * Delete property from documentation if we delete object * @param string $file file or path @@ -661,7 +632,8 @@ function deletePropsFromDoc($file, $objectname) $start = "== Table of fields and their properties for object *".ucfirst($objectname)."* : "; $end = "== end table for object ".ucfirst($objectname); - $string = getFromFile($file, $start, $end); - dolReplaceInFile($file, array($string => '')); - dolReplaceInFile($file, array($start => '', $end => '')); + $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); } From fcbae93328e4e95ea65a6e29f00cad48e9661339 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Tue, 21 Mar 2023 16:00:50 +0100 Subject: [PATCH 3/4] add function writePropsInAsciiDoc when Init object if doc was generated --- htdocs/modulebuilder/index.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 82542691f2c..5fdcb307100 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1586,6 +1586,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 From 2b14d74cf1d0fed544633ad870bf1d5ecdc5af25 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 24 Mar 2023 18:42:13 +0100 Subject: [PATCH 4/4] update function deletewrite --- htdocs/core/lib/modulebuilder.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 5b5de104d3d..9d937d67627 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -613,6 +613,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) { @@ -631,7 +632,7 @@ function deletePropsFromDoc($file, $objectname) { $start = "== Table of fields and their properties for object *".ucfirst($objectname)."* : "; - $end = "== end table 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);