You are here

TECHINFO.txt in Taxonomy CSV import/export 6.4


                  TAXONOMY CSV IMPORT/EXPORT TECHNICAL INFOS
                  ==========================================



- Files of module
- Detail of files
- Use as an api
- Logical structure
- Add a new scheme


-- FILES OF MODULE --
  -----------------

Taxonomy csv module is divided in files in order to minimize memory and to use
it as an api. Here an explanation of structure of these files.


Default Drupal files
                                             .info
                                            .install
                                             .module
                                                |
                              ------------------+------------------
                              |                                   |
                              V                                   V
User Interface use -> .import.admin.inc                   .export.admin.inc
                              |                                   |
                              ------------------+------------------
                                                |
                                                V
                                            .api.inc
                                          *.format.inc
                                                |
                              ------------------+------------------
                              |                                   |
                              V                                   V
API use ---------->    .import.api.inc                     .export.api.inc
                   .import.parser.api.inc                         |
                    .import.line.api.inc                          |
                              |                                   |
                              ------------------+------------------
                                                |
                                                V
                                            .api.inc
                                          *.format.inc
                    .vocabulary.api.inc         |
                                         .term.api.inc
                                                |
Only if user wants result infos and stats       |
                              ------------------+------------------
                              |                                   |
                              V                                   V
                    .import.result.inc                    .export.result.inc
                              |                                   |
                              ------------------+------------------
                                                |
                                                V
                                           .result.inc


-- DETAILS OF FILES --
  ------------------

- Default Drupal files
  - .info                 : info on module
  - .install              : install/uninstall
  - .module               : manage help, permissions and menus

- Central file
  - .api.inc              : manage variables and features of module. It is
                            invoked by below files.

- User interface files
  - .import.admin.inc     : create import form and validate user input
  - .export.admin.inc     : create export form and validate user input

- Api files
  - .import.api.inc       : validate import options and manage import process
  - .import.parser.inc    : Check a line of imported terms: duplicate, format...
                            Can be excluded if user doesn't want to check lines.
  - .import.line.inc      : process import of a csv line, i.e. of a term or a
                            list of terms
  - .export.api.inc       : validate export options, manage and process export
                            of a vocabulary (no need of a check)
  - .vocabulary.api.inc   : prepare and manage vocabularies
  - .term.api.inc         : find and get full or detail term definitions, and
                            save term

- Result files
  - .result.inc           : manages common messages on results of process
  - .import.result.inc    : manage infos and stats about import
  - .export.result.inc    : manage infos and stats about export

- Format files
  - *.format.inc          : contain full functions to import/export a vocabulary


-- USE AS AN API --
  ---------------

- Taxonomy_csv module doesn't need to be enabled. If it is not enabled, it need
  to be invoked directly as this (example for import):
    // Invoke taxonomy_csv import api.
    $module_dir = drupal_get_path('module', 'taxonomy_csv');
    require_once("$module_dir/import/taxonomy_csv.import.api.inc");
  Other needed files are automaticaly invoked.

- If you choose to copy needed taxonomy_csv files in your module, they need to
  be invoked by your module.info or directly with require_once. To include api
  such this is  possible, but not recommended, because some changes may be done
  on taxonomy_csv files : each path of "require_once" should be modified.

- If Drupal core taxonomy module is not activated, main files of this module
  should be invoked in your module as this:
    // Invoke taxonomy core api.
    $taxonomy_path = drupal_get_path('module', 'taxonomy');
    require_once("$taxonomy_path/taxonomy.module");
    require_once("$taxonomy_path/taxonomy.admin.inc");
    require_once("$taxonomy_path/taxonomy.api.php"); // Drupal 7 only.

- Example (import of three lines in a new vocabulary with internal invocation):
    // Invoke taxonomy_csv.api if not included in module.info or enabled.
    $module_dir = drupal_get_path('module', 'taxonomy_csv');
    require_once("$module_dir/import/taxonomy_csv.import.api.inc");

    $csv_lines = '"Europe", "France", "Paris"';
    $csv_lines .=  "\n". ',, "Lyon"';
    $csv_lines .=  "\n". ',"United Kingdom", "London"';
    $csv_lines .=  "\n". ',"Portugal", "Lisbonne"';
    $result = taxonomy_csv_import(
      array(
        'text'           => $csv_lines,
        'import_format'  => 'tree_structure',
        'existing_items' => 'update_replace',
    ));

- Others functions of api can be used too (line_import, export, vocabulary...).


-- LOGICAL STRUCTURE --
  -------------------

Functions sets:
  1a. Prepare and import a vocabulary : taxonomy_csv_vocabulary_import
  1b. Prepare and export a vocabulary : taxonomy_csv_vocabulary_export
  2a. Prepare and import a line       : taxonomy_csv_line_import
  2b. Prepare and export a term       : taxonomy_csv_term_export
  3a. Prepare and import a term       : taxonomy_csv_term_import
  3b. Prepare and export a line       : taxonomy_csv_line_export
  4.  Errors helpers
  5.  Infos and log messages


Structure of import Api:
  1. Batch prepare import of file or text
  2. Process import structure (line by line import from a batch set)
    1. Validate line if wanted
      1. Clean input line
      2. Check line items
    2. Prepare to process items matching import type
    3. Process import
      1. Find previous or existing term, switch case:
        - in part of vocabulary if structure import (parent)
        - in whole vocabulary
        - in all vocabularies if external term referenced
      2. Update or create term
    4. Check import and save messages if wanted
  3. Evaluate vocabulary and finish process


Structure of export Api:
  1. Batch prepare of vocabulary
  2. Export depending on format


-- ADD A NEW SCHEME --
  ------------------

You can add a new csv scheme either by include it in module, either as plug-in.
To include it in module, you need:
 - a define without space,
 - features items in _taxonomy_csv_values (.api.inc file),
 - items in taxonomy_csv.js and taxonomy_csv.css (Drupal 6 only),
 - a description in appropriate forms (.module, .admin.inc files),
 - an advanced help (.help.html),
 - a case in _taxonomy_csv_check_items(),
 - a case in taxonomy_csv_import_line_items(),
 - eventually specific options.
 - a case in taxonomy_csv_export_line_items() if possible.

To include it as plug-in, you need to add a formatted inc file in "formats" sub
directory. File must be named with format NAME followed by '.format.inc'. This
file should contain some functions. Only the first is required, others are
needed to process an import or an export or when there are specific fields.
 - taxonomy_csv_format_NAME describing format and available functions.
   - 'format'        : format name
   - 'name'          : name displayed
   - 'needed_module' : required module to use if there are non standard fields
   - 'import_format' : name displayed if available, else nothing
   - 'export_format' : name displayed if available, else nothing
   - 'import_allowed': options to use for existing terms when importing terms
   - 'import_previous': TRUE or FALSE if format uses specific previous items
   - 'specific_fields': TRUE or FALSE if format use specific fields
   - 'description'   : short description of format
   - 'description_format': oredred list of fields
   - 'description_example': a working example of the format
   - 'description_long': long description of format
   - 'import_options_help': explanation of options for existing terms
 - _vocabulary_check_NAME to check if vocabulary has specific fields.
 - _import_vocabulary_prepare_NAME if special fields are needed.
 - _line_import_check_NAME to check quality of line items.
 - _line_import_NAME to process true import.
 - _term_import_NAME if format has specific fields.
 - _line_export_NAME if format provides export schema.
 - _term_export_NAME if format provides export schema.
 - _term_load_NAME to get full term.
 - _term_load_NAME to get full term.
 - _term_get_full_NAME to complete a term with specific fields.
 - _term_get_NAME to get only specific fields.
Furthermore, you need:
 - items in taxonomy_csv.js and taxonomy_csv.css (Drupal 6 only).
 - items in main help taxonomy_csv.help.html.
 - translations.

See 'geotaxonomy' and 'taxonomy_manager' examples.

File

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