From 742890157a1d252fdcece194ecd112c750cbf194 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Mon, 20 Mar 2023 19:43:23 +0100 Subject: [PATCH] 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'];