TECHINFO.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. TAXONOMY CSV IMPORT/EXPORT TECHNICAL INFOS
  2. ==========================================
  3. @todo To be updated for >= 7.x.5.8
  4. Taxonomy csv import/export module has a lot of files, but majority of them are
  5. used for user interface, to check the input and to manage big taxonomies import.
  6. Furthermore, the process of duplicate terms is complex and code can be largely
  7. simplified if these terms are not allowed - what is advised - and, therefore,
  8. not to be managed.
  9. True import/export process is done by some main functions only.
  10. - Files of module
  11. - Detail of files
  12. - Use as an api
  13. - Logical structure
  14. - Add a new scheme
  15. -- FILES OF MODULE --
  16. -----------------
  17. Taxonomy csv module is divided in files in order to minimize memory and to use
  18. it as an api. Here an explanation of structure of these files.
  19. Default Drupal files
  20. .info
  21. .install
  22. .module
  23. |
  24. ------------------+------------------
  25. | |
  26. V V
  27. User Interface use -> .import.admin.inc .export.admin.inc
  28. | |
  29. ------------------+------------------
  30. |
  31. V
  32. .api.inc
  33. *.format.inc
  34. |
  35. ------------------+------------------
  36. | |
  37. V V
  38. API / Drush use -----> .import.api.inc .export.api.inc
  39. .import.parser.api.inc |
  40. .import.line.api.inc |
  41. | |
  42. ------------------+------------------
  43. |
  44. V
  45. .api.inc
  46. *.format.inc
  47. .vocabulary.api.inc |
  48. .term.api.inc
  49. |
  50. Only if user wants result infos and stats |
  51. ------------------+------------------
  52. | |
  53. V V
  54. .import.result.inc .export.result.inc
  55. | |
  56. ------------------+------------------
  57. |
  58. V
  59. .result.inc
  60. -- DETAILS OF FILES --
  61. ------------------
  62. - Default Drupal files
  63. - .info : info on module
  64. - .install : install/uninstall
  65. - .module : manage help, permissions and menus
  66. - Central file
  67. - .api.inc : manage variables and features of module. It is
  68. invoked by below files.
  69. - User interface files
  70. - .import.admin.inc : create import form and validate user input
  71. - .export.admin.inc : create export form and validate user input
  72. - Api files
  73. - .import.api.inc : validate import options and manage import process
  74. - .import.parser.inc : Check a line of imported terms: duplicate, format...
  75. Can be excluded if user doesn't want to check lines.
  76. - .import.line.inc : process import of a csv line, i.e. of a term or a
  77. list of terms
  78. - .export.api.inc : validate export options, manage and process export
  79. of a vocabulary (no need of a check)
  80. - .vocabulary.api.inc : prepare and manage vocabularies
  81. - .term.api.inc : find and get full or detail term definitions, and
  82. save term
  83. - Result files
  84. - .result.inc : manages common messages on results of process
  85. - .import.result.inc : manage infos and stats about import
  86. - .export.result.inc : manage infos and stats about export
  87. - Format files
  88. - *.format.inc : contain full functions to import/export a vocabulary
  89. -- USE AS AN API --
  90. ---------------
  91. - Taxonomy_csv module doesn't need to be enabled. If it is not enabled, it need
  92. to be invoked directly as this (example for import):
  93. // Invoke taxonomy_csv import api.
  94. $module_dir = drupal_get_path('module', 'taxonomy_csv');
  95. require_once("$module_dir/import/taxonomy_csv.import.api.inc");
  96. Other needed files are automaticaly invoked.
  97. - If you choose to copy needed taxonomy_csv files in your module, they need to
  98. be invoked by your module.info or directly with require_once. To include api
  99. such this is possible, but not recommended, because some changes may be done
  100. on taxonomy_csv files : each path of "require_once" should be modified.
  101. - If Drupal core taxonomy module is not activated, main files of this module
  102. should be invoked in your module as this:
  103. // Invoke taxonomy core api.
  104. $taxonomy_path = drupal_get_path('module', 'taxonomy');
  105. require_once("$taxonomy_path/taxonomy.module");
  106. require_once("$taxonomy_path/taxonomy.admin.inc");
  107. require_once("$taxonomy_path/taxonomy.api.php"); // Drupal 7 only.
  108. - Example (import of three lines in a new vocabulary with internal invocation):
  109. // Invoke taxonomy_csv.api if not included in module.info or enabled.
  110. $module_dir = drupal_get_path('module', 'taxonomy_csv');
  111. require_once("$module_dir/import/taxonomy_csv.import.api.inc");
  112. $csv_lines = '"Europe", "France", "Paris"';
  113. $csv_lines .= "\n". ',, "Lyon"';
  114. $csv_lines .= "\n". ',"United Kingdom", "London"';
  115. $csv_lines .= "\n". ',"Portugal", "Lisbonne"';
  116. $result = taxonomy_csv_import(
  117. array(
  118. 'text' => $csv_lines,
  119. 'import_format' => 'tree_structure',
  120. 'existing_items' => 'update_replace',
  121. ));
  122. - Others functions of api can be used too (line_import, export, vocabulary...).
  123. -- LOGICAL STRUCTURE --
  124. -------------------
  125. Functions sets:
  126. 1a. Prepare and import a vocabulary : taxonomy_csv_vocabulary_import
  127. 1b. Prepare and export a vocabulary : taxonomy_csv_vocabulary_export
  128. 2a. Prepare and import a line : taxonomy_csv_line_import
  129. 2b. Prepare and export a term : taxonomy_csv_term_export
  130. 3a. Prepare and import a term : taxonomy_csv_term_import
  131. 3b. Prepare and export a line : taxonomy_csv_line_export
  132. 4. Errors helpers
  133. 5. Infos and log messages
  134. Structure of import Api:
  135. 1. Batch prepare import of file or text
  136. 2. Process import structure (line by line import from a batch set)
  137. 1. Validate line if wanted
  138. 1. Clean input line
  139. 2. Check line items
  140. 2. Prepare to process items matching import type
  141. 3. Process import
  142. 1. Find previous or existing term, switch case:
  143. - in part of vocabulary if structure import (parent)
  144. - in whole vocabulary
  145. - in all vocabularies if external term referenced
  146. 2. Update or create term
  147. 4. Check import and save messages if wanted
  148. 3. Evaluate vocabulary and finish process
  149. Structure of export Api:
  150. 1. Batch prepare of vocabulary
  151. 2. Export depending on format
  152. -- ADD A NEW SCHEME --
  153. ------------------
  154. You can add a new csv scheme either by include it in module, either as plug-in.
  155. To include it in module, you need:
  156. - a define without space,
  157. - features items in _taxonomy_csv_values (.api.inc file),
  158. - items in taxonomy_csv.js and taxonomy_csv.css (Drupal 6 only),
  159. - a description in appropriate forms (.module, .admin.inc files),
  160. - an advanced help (.help.html),
  161. - a case in _taxonomy_csv_check_items(),
  162. - a case in taxonomy_csv_import_line_items(),
  163. - eventually specific options.
  164. - a case in taxonomy_csv_export_line_items() if possible.
  165. To include it as plug-in, you need to add a formatted inc file in "formats" sub
  166. directory. File must be named with format NAME followed by '.format.inc'. This
  167. file should contain some functions. Only the first is required, others are
  168. needed to process an import or an export or when there are specific fields.
  169. - taxonomy_csv_format_NAME describing format and available functions.
  170. - 'format' : format name
  171. - 'name' : name displayed
  172. - 'needed_module' : required module to use if there are non standard fields
  173. - 'import_format' : name displayed if available, else nothing
  174. - 'export_format' : name displayed if available, else nothing
  175. - 'import_allowed': options to use for existing terms when importing terms
  176. - 'import_previous': TRUE or FALSE if format uses specific previous items
  177. - 'specific_fields': TRUE or FALSE if format use specific fields
  178. - 'description' : short description of format
  179. - 'description_format': oredred list of fields
  180. - 'description_example': a working example of the format
  181. - 'description_long': long description of format
  182. - 'import_options_help': explanation of options for existing terms
  183. - _vocabulary_check_NAME to check if vocabulary has specific fields.
  184. - _import_vocabulary_prepare_NAME if special fields are needed.
  185. - _line_import_check_NAME to check quality of line items.
  186. - _line_import_NAME to process true import.
  187. - _term_import_NAME if format has specific fields.
  188. - _line_export_NAME if format provides export schema.
  189. - _term_export_NAME if format provides export schema.
  190. - _term_load_NAME to get full term.
  191. - _term_load_NAME to get full term.
  192. - _term_get_full_NAME to complete a term with specific fields.
  193. - _term_get_NAME to get only specific fields.
  194. Furthermore, you need:
  195. - items in taxonomy_csv.js and taxonomy_csv.css (Drupal 6 only).
  196. - items in main help taxonomy_csv.help.html.
  197. - translations.
  198. See 'geotaxonomy' and 'taxonomy_manager' examples.