![]() |
DocDB module documentation |
echo function displays text on the browser screen, strpos gives the position of a string within another string, and sort sorts an array of values. These functions are numerous and cover almost all the problems developers encounter.opendir, readdir, or readfile, which read directories or files contained on the server's disk, and exif_read_data, imagejpeg, or getimagesize, which handle images. There are many more functions, and I have identified 99 of them as of now.blobs, which did not appear early in the history of databases, whereas dealing with large files was a problem solved early on in the design of file systems.blobs is now running well, and it is advantageous to use it in Dolibarr.opendir is replaced by opendir_Bypass. Where opendir opened a directory on the disk, opendir_Bypass opens and reads a table in the database. This is called an emulator. The original functions are emulated by the emulation functions. They produce the same results but with a completely different underlying method, and the same approach is applied to all functions related to documents. A more modern terminology might refer to it as aspect-oriented programming.install.lock file, and the necessary api subdirectory for certain operations. In any case, it no longer stores anything, and the documents can be deleted. They are now stored in two tables (llx_doc_data and llx_doc_directory) and are naturally associated with any operation related to the database.docDBmigrateScripts.py and docDBmigrateFiles.py), each of which is used once. The first one modifies the Dolibarr script code, and the second one extracts the documents from the directory and loads them into the database. These two operations are reversible, allowing testing and rollback if necessary.install-en_EN.html) delivered with the module. The operation is quite simple and fast for those with minimal command-line experience.
--reverse option to recreate the same documents, only non-empty directories will be generated. In reality, this has no significant impact because Dolibarr can create a directory when it needs to, and it does not affect its functionality.docDBmigrateScripts.py to migrate your module. The command will only see the modifications to be made in the module since the Dolibarr scripts will have already been migrated. Feel free to use the --dry-run option during the first attempt to visualize what will happen.| Module | Version | Test date | Tester's name |
|---|---|---|---|
| Scanner | 17.0.0 | 15/05/2023 | jmbc |
| List of operations included in the protocol : |
| - docDB migration |
| - document comparison : initial / after reverse |
| - adding/removing logo |
| - accented characters in document name |
| - verification of generating PDF customer invoices |
| - access to document thumbnails |
| - access to complete documents |
| - storage of third-party documents |
| - cropping of third-party documents |
| - storage of project documents |
| - EDM space: folder creation |
| - EDM space: file upload |
| - EDM space: sub-folder creation |
| - EDM space: folder/sub-folder deletion |
| - EDM space: rename folder/sub-folder/folder with files |
| - EDM space: rename file with accents |
| - EDM space: automatic folder structure - development |
| - EDM space: automatic folder structure - preview |
| - EDM space: automatic folder structure - access to customer invoices |
| - EDM space: automatic folder structure - access to projects |
| - EDM space: automatic folder structure - access to third parties |
| - test suite - creation of 10 clients via API |
| - test suite - creation of 100 invoices per client |
| - test suite - download of 100 documents per client |
| - access to documents after reverse |
select default_character_set_name from information_schema.schemata where schema_name = "dolibarr_base_name";utf8mb4 or utf8mb3É is different from E, à is different from a, etc.), whereas they are considered equivalent in an SQL query. This is problematic for emulating file system behavior in an SQL query, which is why docDB uses CHARSET=utf8 COLLATE=utf8_bin to achieve the desired results.
install-en_EN.html provided with the module for usage examples.| docDBmigrateScripts |
Linux : python3 docDBmigrateScripts.py --dolibarrDir=path_name [--reverse] [--dry-run]Windows : py -X utf8 docDBmigrateScripts.py --dolibarrDir=path_name [--reverse] [--dry-run]Modifies the content of the scripts in the Dolibarr htdocs directory in order to enable database access. For example, an instruction sequence like if (file_exists($file)) will be transformed into if (file_exists_Bypass($file)). This process is applied to all PHP scripts, except those copied from the install/scriptFiles folder of docDB.The --reverse option restores the scripts to their original state
|
|
|---|---|---|
| --dolibarrDir | Full path to the Dolibarr htdocs Dolibarr directory.If Dolibarr is located at /var/www/dolibarr, then --dolibarrDir= should point to /var/www/dolibarr/htdocs |
|
| --reverse | Restores the PHP scripts of Dolibarr to their initial state. Note that this is not a restoration from backup files, but rather a reverse processing of the scripts found in the folder. |
|
| --dry-run | Requests a test processing. The algorithm is followed exactly until the point of modifying the processed element, which is ultimately not modified. |
|
| -X utf8 | Windows. Instructs Python to use the UTF-8 character set in the script | |
| docDBmigrateFiles |
Linux : python3 docDBmigrateFiles.py --dolibarrDir=path_name [--reverse] [--dry-run]Windows : py -X utf8 docDBmigrateFiles.py --dolibarrDir=path_name [--reverse] [--dry-run] [--phpdir=php_binaries_path]This command reads the contents of the Dolibarr documents directory and loads it into the database. The directory path is obtained from the $dolibarr_main_data_root variable in the Dolibarr configuration file (htdocs/conf/conf.php). This file also provides the database access parameters.If a file is reported as missing, a correction should be made either in the database (table llx_ecm_files) or in the directory where the file is missing. The corrective action is preferable to avoid future issues during operation. For example, you can use an SQL command like delete from llx_ecm_files where filename like '%missing_file_name%'; to remove a reference to a non-existing document. In this case, first verify the safety of the query using a select command like select filepath,filename from llx_ecm_files where filename like '%missing_file_name%'; to list any unrelated documents that might be mistakenly deleted.
|
|
|---|---|---|
| --dolibarrDir | Full path to the Dolibarr htdocs directory.If Dolibarr is located at /var/www/dolibarr, then --dolibarrDir should point to /var/www/dolibarr/htdocs. |
|
| --reverse | Loads the EDM documents from the database back to the Dolibarr documents directory. | |
| --dry-run | Requests a test processing. The algorithm is followed exactly until the point of modifying the processed element, which does not occur. |
|
| -X utf8 | Windows. Instructs Python to use the UTF-8 character set in the script. | |
| --phpdir | Windows. Specifies the path to the PHP executable for Python. This option is required if the PHP executable path is not in the Windows PATH. Access to PHP is used to obtain certain characteristics of image files that are read in real-time by Dolibarr and not stored in the database. In contrast, docDB stores this data in the database to serve it to Dolibarr when requested.
|
|
| SQL query | Example result | Explanation |
|---|---|---|
select * from llx_doc_directory; |
| rowid | path_name |
| 1 | |
| 2 | /adherent |
| 3 | /adherent/1 |
| 4 | /adherent/10 |
| 5 | /adherent/11 |
|
The docDB table llx_doc_directory contains the list of directories that are supposed to contain the documents.
|
select rowid,path_name,filemtime, |
| rowid | path_name | filemtime | filesize | exif_data | imagesize |
| 1 | /adherent/1/Jean.pdf | 2023-01-27 21:36:39 | 153092 | 4 | 4 |
| 2 | /adherent/10/Jeanne.pdf | 2023-01-27 21:36:39 | 44421 | 4 | 4 |
| 3 | /adherent/11/Léo.pdf | 2023-01-30 09:56:36 | 16135 | 4 | 4 |
| 4 | /adherent/14/Charlie.pdf | 2023-01-30 09:56:18 | 25034 | 4 | 4 |
| 5 | /adherent/2/Arthur.pdf | 2023-01-27 21:36:39 | 44844 | 4 | 4 |
|
The docDB table llx_doc_data contains the documents. The datablob column is not displayable. Instead, filesize indicates the size of the document. exif_data and imagesize are encoded strings containing image characteristics if applicable (empty in the case of PDF files).
|
select filepath,filename from llx_ecm_files; |
| filepath | filename |
| adherent/1 | Jean.pdf |
| adherent/10 | Jeanne.pdf |
| adherent/11 | Léo.pdf |
| adherent/14 | Charlie.pdf |
| adherent/2 | Arthur.pdf |
|
The Dolibarr table llx_ecm_files contains the list of documents and the corresponding filepaths. |
select label from llx_ecm_directories; |
| label |
| Annual documents |
|
The Dolibarr table llx_ecm_directories contains the list of certain directories, those created by users in the EDM space. |
file_exists, which is transformed by docDB into file_exists_Bypass. In short, this function executes the query select rowid from llx_doc_data where path_name='/invoice/FA2304-0001/FA2304-0001.pdf'. If the query is successful, meaning the document exists in the llx_doc_data table, docDB returns the value true.filectime to determine the creation date of a file. This occasionally happens but never for a document. The corresponding docDB function filectime_Bypass simply calls PHP and returns the result obtained from PHP back to Dolibarr.filectime_Bypass. This would involve testing if the relevant file is a document (if ($useByPass && doc_in_db($filename))), and in that case, using the appropriate SQL query. The docDB functions are relatively simple, and their use and extension are within the reach of a reasonably experienced PHP programmer.docDBmigrateScripts.py script, in the variable KEYWORDS_FOUND_16.filebypass.php after the comment The following functions are not used in the Dolibarr documents context.
LOG_DEBUG(7).2023-05-12 15:00:02 DEBUG n.n.n.n DOC_DB ++ filesize /project/PJ2303-0025/contract_signed [370816]. In this example, the mention DOC_DB ++ indicates the call to the filesize function for the document /project/PJ2303-0025/contract_signed, returning a size of 370816.
If the mention is DOC_DB --, it indicates that the returned data is from PHP without any specific processing performed by docDB.docDBmigrateFiles.py script on Windows, you may encounter a crash with a fieldnotfound error message. This indicates that you need to specify the PHP path using the --phpdir option.exif_data option is properly enabled. You can follow the procedure explained in the installation guide for this purpose.
COPYING file for more details.