taxonomy_csv.result.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /**
  3. * @file
  4. * Manage messages on results of import or export process.
  5. */
  6. /**
  7. * Helper to determine drupal_set_message type level from Drupal watchdog level.
  8. *
  9. * As drupal_set_message uses only three types, a mapping is needing when we
  10. * have only a watchdog level.
  11. * @see bootstrap.inc
  12. *
  13. * @param $watchdog_level
  14. * Integer. Watchdog level as defined in bootstrap.inc.
  15. *
  16. * @return
  17. * drupal_set_message type level.
  18. */
  19. function _taxonomy_csv_message_watchdog_type($watchdog_level) {
  20. $mapping = array(
  21. WATCHDOG_ERROR => 'error', // Stop import process.
  22. WATCHDOG_WARNING => 'error', // Stop line process and go next.
  23. WATCHDOG_NOTICE => 'warning', // Continue current line process.
  24. WATCHDOG_INFO => 'status', // Successfully processed.
  25. WATCHDOG_DEBUG => 'status', // Internal use only.
  26. );
  27. return $mapping[$watchdog_level];
  28. }
  29. /**
  30. * Helper to determine error level of a message code.
  31. *
  32. * @param $message_code
  33. * Single message code (000 to 799).
  34. *
  35. * @return
  36. * Level (0 to 7).
  37. */
  38. function _taxonomy_csv_message_get_level($message_code) {
  39. $result = intval($message_code / 100);
  40. return ($result >= WATCHDOG_ERROR && $result <= WATCHDOG_DEBUG) ?
  41. $result :
  42. WATCHDOG_ERROR;
  43. }
  44. /**
  45. * Helper to display result messages.
  46. *
  47. * @param $messages
  48. * Array of messages array. A message array contains a watchdog level and a
  49. * message code. A message code is an integer between 000 and 799.
  50. *
  51. * @return
  52. * Nothing.
  53. */
  54. function _taxonomy_csv_message_result($messages) {
  55. foreach ($messages as $message) {
  56. $type = key($message);
  57. drupal_set_message($message[$type], _taxonomy_csv_message_watchdog_type($type));
  58. }
  59. }
  60. /**
  61. * Helper to display by line list of result messages.
  62. *
  63. * @param $messages_set
  64. * Array of message codes by line.
  65. * Message code is an integer between 000 and 799.
  66. *
  67. * @return
  68. * Array of messages.
  69. */
  70. function _taxonomy_csv_message_result_by_line($messages_set) {
  71. $messages = array();
  72. if (is_array($messages_set) && $messages_set) {
  73. foreach ($messages_set as $line_number => $message_codes) {
  74. $processed_message_level = _taxonomy_csv_message_get_level(_taxonomy_csv_worst_message($message_codes));
  75. $processed_message_text = t('Line #!line_number:', array('!line_number' => $line_number)) . '<br />';
  76. foreach ($message_codes as $message_code) {
  77. $processed_message_text .= _taxonomy_csv_message_text($message_code) . '<br />';
  78. }
  79. $messages[] = array($processed_message_level => $processed_message_text);
  80. }
  81. }
  82. return $messages;
  83. }
  84. /**
  85. * Helper to display compact list of result messages.
  86. *
  87. * @param $messages_set
  88. * Array of operation array of codes, except 691, 692 and 695.
  89. * Message code is an integer between 000 and 799.
  90. *
  91. * @return
  92. * Array of messages.
  93. */
  94. function _taxonomy_csv_message_result_by_message($messages_set) {
  95. $messages = array();
  96. if (is_array($messages_set) && $messages_set) {
  97. // Convert [line number][message codes]
  98. // to [message codes][line number].
  99. foreach ($messages_set as $line_number => $operation) {
  100. foreach ($operation as $message_code) {
  101. $list_messages[$message_code][] = $line_number;
  102. }
  103. }
  104. ksort($list_messages);
  105. foreach ($list_messages as $message_code => $line_numbers) {
  106. // Only show line level message with created, updated and unchanged terms.
  107. if (($message_code != 691) && ($message_code != 692) && ($message_code != 695)) {
  108. $processed_message_level = _taxonomy_csv_message_get_level($message_code);
  109. $processed_message_text = _taxonomy_csv_message_text($message_code) . ' ' . t('Lines:') . '<br />' . implode(', ', $line_numbers) . '.';
  110. $messages[] = array($processed_message_level => $processed_message_text);
  111. }
  112. }
  113. }
  114. return $messages;
  115. }
  116. /**
  117. * Helper to get text of a message with a message code.
  118. *
  119. * @param $message_code
  120. * Message codes are integer between 000 and 799.
  121. *
  122. * @return
  123. * Message text string.
  124. */
  125. function _taxonomy_csv_message_text($message_code) {
  126. // Static used only for performance reason.
  127. static $watchdog_messages;
  128. if (!isset($watchdog_messages)) {
  129. // These variables are used to simplify strings management and translation.
  130. $error = ' ' . t("Import process is stopped.");
  131. $warning = ' ' . t("This line won't be processed.");
  132. $notice = ' ' . t("Line is processed.");
  133. $watchdog_messages = array(
  134. // Format: Level, Type of import, Serial.
  135. 300 => t('ERROR'),
  136. 301 => t("Wrong code. Module is not installed correctly. Please reinstall module from a fresh release or submit an issue."),
  137. 302 => t('Unreferenced code. Please reinstall module from a fresh release or submit an issue.'),
  138. 305 => t('Error in options.'),
  139. 306 => t('Unknown import format. Change "Source content" option.') . $error,
  140. 307 => t('Unknown export format. Change "Export format" option.') . $error,
  141. 310 => t("You choose to import a taxonomy by a file, but you don't set its name or its size is greater than the server's limit.") . $error,
  142. 311 => t('Size of your file is null.') . $error,
  143. 312 => t('Unable to write to file.') . $error,
  144. 313 => t('Current line is multiline or contains delimiter, enclosure or unprotected line ending. Change the content of the term, or set appropriate format settings in second tab.'),
  145. 320 => t("Your file can't be converted to utf-8. Please install iconv, GNU recode or mbstring for PHP or convert your file to utf-8 and disable 'Enable utf-8 conversion' option.") . $error,
  146. 321 => t('Despite your option, your file is not recognize as an UTF-8 encoded one. Convert it before submit it.') . $error,
  147. 340 => t("Vocabulary doesn't exist."),
  148. 341 => t("Field doesn't exist in this vocabulary.") . $error,
  149. 352 => t("A parent tid is given, but it hasn't been imported in a previous line.") . $error,
  150. 360 => t('An error occurs during translation of term.') . $error,
  151. 361 => t('You cannot import translated terms into a vocabulary without language or with a fixed language.') . $error,
  152. 385 => t('No term to export.'),
  153. 390 => t('No line to import. Please first check your file and file uploading, else reinstall module from a fresh release or submit an issue.') . $error,
  154. 391 => t('No term to import. Please first check your file and file uploading, else reinstall module from a fresh release or submit an issue.') . $error,
  155. 392 => t('Problem when caching imported term. Please first check your file and file uploading, else reinstall module from a fresh release or submit an issue.') . $error,
  156. 400 => t('WARNING'),
  157. 402 => t('Unable to import a field term.') . $warning,
  158. 405 => t('Unmanaged option.') . $warning,
  159. 408 => t('Number of terms is invalid. Check if all your terms are attached to an existing vocabulary. The module exports only good terms and skips the others automatically.'),
  160. 410 => t("Impossible to get parent of first item, because previous line has less parent(s). You may add one or more parents to current line or change lines order.") . $warning,
  161. 430 => t('Line contains empty items.') . $warning,
  162. 431 => t('Line contains duplicate items.') . $warning,
  163. 432 => t('Line contains an empty term. Only items before this one have been imported.'),
  164. 433 => t("Line contains items matching term name. A term can't be synonym, related, parent or child of itself.") . $warning,
  165. 434 => t('Line contains too many items.') . $warning,
  166. 435 => t('Line contains a translation for an empty description.') . $warning,
  167. 440 => t("Vocabulary doesn't exist. When you duplicate or import into an existing vocabulary, option 'vocabulary_id' should contains true vocabulary id.") . $warning,
  168. 450 => t('Weight in second column is not an allowed number.') . $warning,
  169. 451 => t('One or more items are not numbers.') . $warning,
  170. 452 => t('A term cannot be a parent of itself.') . $warning,
  171. 453 => t('A term has no semantic field parent.'),
  172. 454 => t('Term name or id is longer than 255 characters. Check field and delimiter.') . $warning,
  173. 455 => t('Unable to make a reference to term "0".') . $warning,
  174. 460 => t('Unknown predicate.') . $warning,
  175. 461 => t('No subject.') . $warning,
  176. 462 => t('No predicate.') . $warning,
  177. 463 => t('No object.') . $warning,
  178. 464 => t('No name.') . $warning,
  179. 465 => t('More than three items.') . $warning,
  180. 466 => t('Unmanaged predicate.') . $warning,
  181. 467 => t('Each semantic field should be imported as "vocabulary" or "root_term".') . $warning,
  182. 480 => t('No first column term to import. Empty first column is allowed only with structure or multiple terms import.') . $warning,
  183. 481 => t('No item in second or third column.') . $warning,
  184. 482 => t("Some items aren't present.") . $warning,
  185. 483 => t('Term without name. Name is the only needed field.') . $warning,
  186. 484 => t('No first or second column. They are required.') . $warning,
  187. 490 => t('No line to import.') . $warning,
  188. 491 => t('No item to import.') . $warning,
  189. 492 => t('Nothing to import.') . $warning,
  190. 493 => t('Empty line.') . $warning,
  191. 499 => t('Warnings have been reported on this line.'),
  192. 500 => t('Notice'),
  193. 501 => t('Too many items. Second and next columns will be ignored, as import choice is to ignore them.'),
  194. 510 => t('Line contains empty items. They are ignored.'),
  195. 511 => t('To change vocabulary of a term is not recommended.'),
  196. 512 => t("Line contains items matching first column term. A term can't be related to itself and a synonym may be different to it.") . ' ' . t('Duplicates will be ignored.'),
  197. 513 => t('Line contains empty items.'),
  198. 520 => t('Unable to load the file attached to the term.'),
  199. 530 => t('Line contains empty items. They will be ignored.'),
  200. 531 => t('Line contains duplicate items or repeated soft tabs.') . ' ' . t('Duplicates or repeated soft tabs will be ignored.'),
  201. 532 => t('Line contains duplicate items.') . ' ' . t('Duplicates are allowed.'),
  202. 533 => t("Line contains items matching term name. A term can't be related, parent, child or synonym to itself.") . ' ' . t('Duplicates will be ignored.'),
  203. 535 => t('Line contains duplicate synonyms.') . ' ' . t('Duplicates will be ignored.'),
  204. 536 => t('Line contains duplicate parents.') . ' ' . t('Duplicates will be ignored.'),
  205. 537 => t('Line contains duplicate children.') . ' ' . t('Duplicates will be ignored.'),
  206. 538 => t('Line contains duplicate related terms.') . ' ' . t('Duplicates will be ignored.'),
  207. 541 => t('Too many items. Third and next columns will be ignored, as a term gets only one description and one weight.'),
  208. 542 => t('Too many items. Fifth and next columns will be ignored.'),
  209. 550 => t("No first column, but line can be processed."),
  210. 551 => t('No parent, so it is a root term.'),
  211. 552 => t('Term has been already imported in a previous line.'),
  212. 553 => t('A semantic field cannot be related to terms.'),
  213. 554 => t('A term has many parents and one is a semantic field, what is impossible.'),
  214. 555 => t('A root term has a parent.') . $notice,
  215. 557 => t('A term cannot be related to a semantic field'),
  216. 558 => t('A semantic field cannot be a term synonym.'),
  217. 559 => t('A term can have only one semantic field.'),
  218. 561 => t('No subject.') . $notice,
  219. 562 => t('No predicate.') . $notice,
  220. 563 => t('No object.') . $notice,
  221. 564 => t('Too many items on the line for the selected format. These items will be ignored.') . $notice,
  222. 565 => t('Some items are empty. Previous items will be used.') . $notice,
  223. 570 => t("Line doesn't contain all needed items.") . $notice,
  224. 580 => t('Be careful. This line has only one term and import choice is to replace existing items. So these items will be removed.'),
  225. 600 => t('Info'),
  226. 605 => t('No error in options.'),
  227. 610 => t('New vocabulary has been created.'),
  228. 611 => t('A vocabulary has been duplicated.'),
  229. 632 => t('Line contains duplicate items.') . ' ' . t('Duplicates are allowed.'),
  230. 639 => t('Line contains empty vocabulary for related terms. They will be created in vocabulary of main term.'),
  231. 640 => t('Vocabulary checked.'),
  232. 662 => t('No predicate.'),
  233. 683 => t('Use of a previous line term.'),
  234. 685 => t('No term to process.'),
  235. 691 => t('Saved new term.'),
  236. 692 => t('Updated term.'),
  237. 693 => t('Removed existing term.'),
  238. 694 => t('Updated new term.'),
  239. 695 => t('Unchanged term.'),
  240. 696 => t('Empty line.'),
  241. 697 => t('Command line.'),
  242. 698 => t('Comment line.'),
  243. 699 => t('Items of the line have been successfully imported.'),
  244. 700 => t('Debug.'),
  245. 799 => t('No message.'),
  246. );
  247. }
  248. if (is_int($message_code) && ($message_code >= 0) && ($message_code <= 799)) {
  249. // Good and referenced code.
  250. if (isset($watchdog_messages[$message_code])) {
  251. $message_title = $watchdog_messages[intval($message_code / 100) * 100];
  252. return $message_title . ' : ' . $watchdog_messages[$message_code];
  253. }
  254. // Else unreferenced code.
  255. return $watchdog_messages[300] . ' : (' . $message_code . ') : ' . $watchdog_messages[302];
  256. }
  257. // Else it's a wrong code.
  258. return $watchdog_messages[300] . ' : (' . $message_code . ') : ' . $watchdog_messages[301];
  259. }