-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcals_importer.module
executable file
·2002 lines (1779 loc) · 65.4 KB
/
cals_importer.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* CALS Importer Module.
*/
/**
* set memory limit and max execution times to higher than normal!
*/
//ini_set('memory_limit', '1024M');
//ini_set('max_execution_time', '600');
//the MARC namespace
define("NAME_SPACE", "http://www.loc.gov/MARC21/slim");
define("MARC_HEADER",
'<collection
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">'
);
//require these files..
module_load_include('inc', 'cals_importer', 'cals_importer.misc');
module_load_include('inc', 'cals_importer', 'cals_importer.fieldcollections');
module_load_include('inc', 'cals_importer', 'cals_importer.mappings');
module_load_include('inc', 'cals_importer', 'cals_importer.marcxml');
module_load_include('inc', 'cals_importer', 'cals_importer.s3paths');
module_load_include('inc', 'cals_importer', 'cals_importer.createrecords');
module_load_include('inc', 'cals_importer', 'cals_importer.clean_up');
module_load_include('inc', 'cals_importer', 'cals_importer.deduper');
module_load_include('inc', 'cals_importer', 'cals_importer.marcxmlfilebuilder');
module_load_include('inc', 'cals_importer', 'cals_importer.exporter');
module_load_include('inc', 'cals_importer', 'cals_importer.corsS3');
module_load_include('inc', 'entity', 'includes/entity.controller');
/**
* Implements hook_menu().
*/
function cals_importer_menu() {
$items = array();
$items['admin/config/cals_importer/normalization'] = array(
'title' => 'Configure normalization settings',
'description' => 'Configuration for the normalization settings in CALS IMPORTER',
'page callback' => 'drupal_get_form',
'page arguments' => array('cals_importer_config_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'file' => 'cals_importer.admin.inc',
);
/*
* Parses S3 sets, can be invoked directly - e.g:
* http://me/cals_staging/admin/content/cals/batch-update-s3-paths/5429
*
* See: content/cals/s3-record-sets
*
*/
$items['admin/content/cals/batch-update-s3-paths'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_batch_update_s3_paths',
'title' => 'Update S3 Paths',
'page arguments' => array(4),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'weight' => 100,
);
/**
* Fix to move OCLC entries out of the system control field
* - deactivated so we don't run accidentally
*/
$items['node/%node/fix-oclc-entry'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_update_oclc_numbers_single_node',
'title' => 'Fix OCLC entry',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'menu-repository-item-processing',
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
);
$items['node/%node/fix-oclc-entry3'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_update_oclc_numbers_single_node',
'title' => 'Fix OCLC entry',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'menu-repository-item-processing',
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
);
/**
* Fix to move OCLC entries out of the system control field
* - deactivated so we don't run accidentally
*/
$items['node/fix-oclc-entry2'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_update_oclc_numbers_single_node',
'title' => 'Fix OCLC entry TEST',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'menu-repository-item-processing',
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
);
$items['node/%node/parse-marcxml-new'] = array(
'page callback' => '_cals_import_skeletal_records',
'title' => "Generate / Update Stub Entries",
'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
);
$items['node/%node/parse-marcxml-new2'] = array(
'page callback' => '_cals_importer_create_repo_items',
'file' => "cals_importer.createrecords.inc",
'title' => "Generate / Update Stub Entries 2",
'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
);
$items['node/%node/preview-titles'] = array(
'page callback' => '_cals_importer_preview_repo_items',
'file' => "cals_importer.createrecords.inc",
'title' => "Preview New Titles in Collection",
'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
);
//generate cors s3 file via s3 path (field collection)
$items['admin/%node/update-file-upload-from-field-collection'] = array(
'page callback' => '_cals_update_filecollection_file',
'title' => "Update via Field Collection",
'type' => MENU_CALLBACK,
'page arguments' => array(1, 3),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
'file' => 'cals_importer.corsS3.inc',
);
//re-parse Publisher from 264 tag
$items['admin/%node/update-publisher-264'] = array(
'page callback' => '_cals_update_publisher_264_tag',
'title' => "Update Publisher Via 264",
'type' => MENU_CALLBACK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
'file' => 'cals_importer.clean_up.inc',
);
//menu callback to provide access to creating the parent xml stub
$items['node/%node/view-xml-stub'] = array(
'page callback' => '_cals_importer_view_marcxml_stub',
'title' => "View XML Stub",
'type' => MENU_LOCAL_TASK,
'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.exporter.inc',
);
//menu callback to provide access to re-validate / view xml stub
$items['node/%node/build-validate-marcxml-output'] = array(
'page callback' => '_cals_importer_exporter_build_marcxml_from_array',
'title' => "Validate / Preview XML Stub",
'type' => MENU_CALLBACK,
'page arguments' => array(1),
'weight' => 100,
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.exporter.inc',
);
//generate cors s3 filesize values
$items['admin/%node/update-filesize-field-collection'] = array(
'page callback' => '_cals_update_filecollection_file_filesize',
'title' => "Update via Field Collection",
'type' => MENU_CALLBACK,
'page arguments' => array(1, 3),
'weight' => 100,
'access arguments' => array('parse s3 paths'),
'file' => 'cals_importer.corsS3.inc',
);
$items['admin/content/cals/files/update-s3-filesizes'] = array(
'title' => 'Update S3 Filesizes',
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_batch_update_filesizes',
'file' => 'cals_importer.corsS3.inc',
'type' => MENU_CALLBACK,
);
//code to build file-snippet
if (module_exists('field_collection')) {
// Add menu paths for viewing/editing/deleting field collection items.
foreach (field_info_fields() as $field) {
if ($field['type'] == 'field_collection' &&
$field['field_name'] == 'field_file_resource' ) {
$path = field_collection_field_get_path($field);
$items[$path . '/%field_collection_item/build_snippet'] = array(
'page callback' => '_cals_importer_exporter_build_marcxml_file_node',
'title' => "Build Snippet",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.exporter_file_snippets.inc',
);
$items[$path . '/%field_collection_item/tmp-test-date-created'] = array(
'page callback' => '_cals_importer_exporter_update_date_created_entity',
'title' => "Copy Date Created (node) to Date Created (file)",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.clean_up.inc',
);
$items[$path . '/%field_collection_item/tmp-test-date-copyrighted'] = array(
'page callback' => '_cals_importer_exporter_update_date_copyrighted_entity',
'title' => "Copy Date Copyrighted (node) to Date Created (file)",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.clean_up.inc',
);
$items[$path . '/%field_collection_item/tmp-test-date-issued'] = array(
'page callback' => '_cals_importer_exporter_update_date_issued_entity',
'title' => "Copy Date Issued (node) to Date Created (file)",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.clean_up.inc',
);
$items[$path . '/%field_collection_item/tmp-test-date-noqualifier'] = array(
'page callback' => '_cals_importer_exporter_update_date_noqualifier_entity',
'title' => "Copy Date No Qualifier (node) to Date Created (file)",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.clean_up.inc',
);
$items[$path . '/%field_collection_item/tmp-test-copy-publisher'] = array(
'page callback' => '_cals_importer_exporter_update_publisher_entity',
'title' => "Update Publisher",
'type' => MENU_LOCAL_TASK,
//'type' => MENU_CALLBACK,
//'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'page arguments' => array(2),
'weight' => 100,
'access arguments' => array('field_collection_item', 2),
'access arguments' => array('view marcxml stub'),
'file' => 'cals_importer.clean_up.inc',
);
}
}
}
$items['_cals_importer_exporter_build_marcxml_file_node'] = array(
'title' => "Add MARC-ready file snippet",
'access arguments' => array('parse s3 paths'),
'page callback' => '_cals_importer_exporter_build_marcxml_file_node',
'file' => "cals_importer.exporter.inc",
'description' => 'Add MARC-ready file snippet',
);
$items['admin/content/nnels_all_export'] = array(
'page callback' => 'drupal_get_form',
'title' => 'NNELS All Record Exporter', //page title
'description' => 'Trigger export of all records in NNELS to AWS S3.',
'page arguments' => array('cals_importer_marcxml_all_exporter_form'),
'access arguments' => array('parse s3 paths'),
);
return $items;
}
/**
* Implements hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function cals_importer_menu_alter(&$items) {
// Removing certain local navigation tabs that are either undesired or need to be custom relocated.
// Set these tabs to MENU_CALLBACK, so they still register the path, but just don't show the tab:
$items['node/%node/parse-access-rights']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/parse-record']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/parse-marcxml-new']['access callback'] = '_cals_importer_tab_checker';
$items['node/%node/parse-marcxml-new2']['access callback'] = '_cals_importer_tab_checker';
$items['node/%node/normalize-publisher']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/normalize-title']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/clean-author']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/generate-marc-856']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/generate-marc-output']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/convert-s3-paths']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/normalize-record']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/fix-oclc-entry']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/normalize-record-preview']['access callback'] = '_cals_importer_tab_checker_parse_record';
$items['node/%node/parse-s3-path-node']['access callback'] = '_cals_importer_tab_checker_parse_s3_paths';
$items['node/%node/view-xml-stub']['access callback'] = '_cals_importer_tab_checker_xmlstub';
}
/**
* Implements hook_permission().
*/
function cals_importer_permission() {
return array(
'dedupe records' => array(
'title' => t('Dedupe Repo Items'),
'description' => t('Dedupe Repo Items.'),
),
'parse s3 paths' => array(
'title' => t('Parse S3 paths'),
'description' => t('Parse S3 Paths.'),
),
'parse marc records' => array(
'title' => t('Parse MARC records'),
),
'view marcxml stub' => array(
'title' => t('View MARC-XML Stub'),
),
'generate repo records' => array(
'title' => t('Generate New Repository Items'),
),
'parse 506' => array(
'title' => t('Parse / Update 506 entries'),
'description' => t(''),
),
'access normalization configuration' => array(
'title' => t('Access normalization configuration'),
'description' => t('Used to configure end of string and other types of stopwords'),
),
);
}
/**
* Implements hook_action_info().
*/
function cals_importer_action_info() {
return array(
//the main MARC XML parser
'_cals_importer_update_repository_items' => array(
'label' => t('1. Generate Full Record (parse MARC XML)'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//Reparse selected fields: hooks into main parser
'_cals_reparse_record_details' => array(
'label' => t('CALS: Re-parse Selected Fields'),
'type' => 'node',
'configurable' => TRUE,
'triggers' => array('any'),
),
'_cals_reparse_file_resource_details' => array(
'label' => t('CALS: Re-parse Selected Fields for File Resource'),
'type' => 'node',
'configurable' => TRUE,
'triggers' => array('any'),
),
//Recalculate fields: hooks into main parser
'_cals_recalc_file_running_time' => array(
'label' => t('CALS: Re-calc File Runtime'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//Reparse accessibility fields on file_resource field collection.
'_cals_reparse_accessibility_details' => array(
'label' => t('CALS: Re-parse Accessibility Fields (Node)'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
'_cals_reparse_accessibility_details_resource' => array(
'label' => t('CALS: Re-parse Accessibility Fields (File Resource)'),
'type' => 'entity',
'configurable' => FALSE,
'triggers' => array('any'),
),
//Copy file resource entities between nodes
'_cals_transfer_file_resource_entity' => array(
'label' => t('Transfer File Resource Entities'),
'type' => 'node',
'configurable' => TRUE,
'triggers' => array('any'),
),
//batch update title field, stripping out trailing slashes, etc.
'_cals_normalize_record_values' => array(
'label' => t('2. Normalize Title, Publisher, Creators'),
'type' => 'node',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//batch update Genre, Subjects.
'_cals_normalize_performer' => array(
'label' => t('CALS: Normalize Performer Values'),
'type' => 'entity',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//batch titlecase creator names
'_cals_titlecase_creators' => array(
'label' => t('CALS: Convert Creators to Title Case'),
'type' => 'entity',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//batch update Genre, Subjects.
'_cals_normalize_taxonomy_terms2' => array(
'label' => t('CALS: Normalize Taxonomy Terms 2'),
'type' => 'taxonomy_term',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//batch copy subject field collection values to simpler subject field
'_cals_copy_field_collection_values_to_subjects' => array(
'label' => t('CALS: Copy Field Collections to Subject Field'),
'type' => 'node',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//batch update Genre, Subjects.
'_cals_normalize_taxonomy_terms' => array(
'label' => t('CALS: Normalize Taxonomy Terms'),
'type' => 'entity',
'configurable' => FALSE, //TRUE,
'triggers' => array('any'),
),
//bulk update to generate marc xml strings w/ 856 tag
'_cals_importer_generate_marc_xml_856' => array(
'label' => t('3. Generate MARC with 856 strings'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch generate MARC XML files and attach to original recordset
'_cals_importer_generate_marcxml_files' => array(
'label' => t('4. Generate downloadable MARC XML files'),
'type' => 'node',
'configurable' => TRUE,
'triggers' => array('any'),
),
//move Publisher into Publisher Source and add new Publisher
'_cals_importer_update_publisher_and_source' => array(
'label' => t('5. Update Publisher and Publisher Source'),
'type' => 'node',
'configurable' => TRUE,
'triggers' => array('any'),
),
//batch generate MARC XML files from search interface
'_cals_importer_generate_marcxml_files_search_interface' => array(
'label' => t('CALS: Generate downloadable MARC XML files (search interface)'),
'type' => 'entity',
'configurable' => TRUE,
'triggers' => array('any'),
),
//preview changes to Author
'_cals_importer_normalize_creators_preview_vbo' => array(
'label' => t("CALS: Preview Creator Normalization"),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch update to just the system control numbers
'_cals_importer_fix_oclc_numbers_batch' => array(
'label' => t("CALS: Fix Dave's STUPID OCLC bug!"),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch update to just the system control numbers
'_cals_importer_update_system_control_numbers' => array(
'label' => t('CALS: Update System Control Numbers'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch update to adjust/update the 506 access rights permissions
'_cals_importer_update_licensed_access' => array(
'label' => t('CALS: Update Access Restrictions'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch dedupe marc xml records
'_cals_dedupe_035' => array(
'label' => t('CALS: Dedupe on 035 matches'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch dedupe org nodes based on ill code (field_library_code)
'_cals_dedupe_orgs_by_illcode' => array(
'label' => t('CALS: Dedupe orgs based on ILL Code matches'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch copy existing S3 paths to Field Collection "field_file_resource"
'_cals_run_batch_update_field_collection_s3_path' => array(
'label' => t('CALS: Copy S3 paths to Field Collection'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
//batch update missing file-size values in Field Collection "field_file_resource"
'_cals_run_batch_update_field_collection_s3_filesizes' => array(
'label' => t('CALS: Batch update S3 Filesize Values'),
'type' => 'entity',
'configurable' => FALSE,
'triggers' => array('any'),
),
//copy date created values in node over to field collection
'_cals_importer_exporter_update_date_created_entity_vbo' => array(
'label' => t('CALS: Copy Node Date (Created / Issued) to Field Collection (FILE)'),
'type' => 'entity',
'configurable' => TRUE,
'triggers' => array('any'),
),
'_cals_importer_exporter_update_publisher_and_datecreated_vbo' => array(
'label' => t('CALS: Copy Date Created and Publisher to Field Collection (FILE)'),
'type' => 'entity',
'configurable' => TRUE,
'triggers' => array('any'),
),
'_cals_importer_exporter_update_publisher_vbo' => array(
'label' => t('CALS: Copy Publisher to Field Collection (FILE)'),
'type' => 'entity',
'configurable' => TRUE,
'triggers' => array('any'),
),
//batch amend broken S3 paths in Field Collection "field_file_resource"
'_cals_mend_broken_file_resource_s3_paths' => array(
'label' => t('Mend Broken S3 paths'),
'type' => 'entity',
'configurable' => TRUE,
'triggers' => array('any'),
),
// Batch copy defunct genres into the harmonized genres (if they exist in
// the taxonomy).
'_cals_move_defunct_genres_into_harmonized' => array(
'label' => t('CALS: Move defunct genres into harmonized'),
'type' => 'node',
'configurable' => FALSE,
'triggers' => array('any'),
),
);
}
/**
* Implements hook_block_info().
*/
function cals_importer_block_info() {
$blocks = array();
$blocks['_cals_importer_process_repo_item'] = array(
'info' => t('CALS Forms: Process Repo Item'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view()
*/
function cals_importer_block_view($delta = '') {
switch ($delta) {
//include with main repo page
case "_cals_importer_process_repo_item":
$block = array();
global $user;
if (arg(0) == 'node') {
$node = node_load(arg(1));
if ($node->type == 'repository_item') {
$block['subject'] = '';
$content = drupal_get_form('_cals_importer_block_process_repo_item');
$block['content'] = $content; //'HERE IN WILL LIE THE ADMIN BLOCK'; //drupal_render(drupal_get_form('user_register_form'));
return $block;
}
}
break;
}
}
function _cals_importer_get_block_items() {
$items = array();
// $items['_cals_importer_update_repository_item'] = array(
// 'access arguments' => array('administer site configuration'),
// 'page callback' => '_cals_importer_update_repository_item',
// 'title' => 'Parse MARC/XML',
// 'file' => "cals_importer.marcxml.inc",
// 'description' => "Item parsed",
// );
// $items['_cals_reparse_titles_edition'] = array(
// 'access arguments' => array('administer site configuration'),
// 'page callback' => '_cals_reparse_title_edition',
// 'file' => "cals_importer.marcxml.inc",
// 'title' => 'Reparse Titles / Edition',
// 'description' => 'Reparses title fields + dc relation field',
//
// );
$items['_cals_normalize_record_value'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_normalize_record_value',
'file' => "cals_importer.clean_up.inc",
'title' => 'Normalize Title, Creator/Contributor, Publisher',
'description' => 'Title, author and publisher values normalized',
);
/*
$items['_cals_normalize_record_value_preview'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_normalize_record_value_preview',
'file' => "cals_importer.clean_up.inc",
'title' => 'Preview Creator Normalization',
'description' => 'No updates: just previewing the normalization',
);
*/
$items['_cals_importer_add_856_tag'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_add_856_tag',
'file' => "cals_importer.clean_up.inc",
'title' => 'Add 856 tag',
'description' => '856 tag added',
);
//code to build stub marc xml output
$items['_cals_importer_create_marc_stub_node'] = array(
'access arguments' => array('parse s3 paths'),
'page callback' => '_cals_importer_create_marc_stub_node',
'file' => "cals_importer.exporter.inc",
'title' => "Build Record Stub",
'description' => 'Created the MARCXML stub',
);
// $items['_cals_importer_exporter_build_marcxml_from_array'] = array(
// 'access arguments' => array('parse s3 paths'),
// 'page callback' => '_cals_importer_exporter_build_marcxml_from_array',
// 'file' => "cals_importer.exporter.inc",
// 'title' => "Build / Validate MARC-XML File",
// 'description' => 'Added MARC-XML File',
// );
/*
$items['_cals_importer_generate_marcxml_file'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_generate_marcxml_file',
'file' => "cals_importer.marcxmlfilebuilder.inc",
'title' => 'Create MARC Output File',
'description' => 'An XML file generated for this node',
); */
$items['_cals_importer_create_marcxml_snippet_file_resource'] = array(
'access arguments' => array('parse s3 paths'),
'page callback' => '_cals_importer_create_marcxml_snippet_file_resource',
'file' => "cals_importer.exporter.inc",
'title' => "Build File Snippet",
'description' => 'Built record snippets per file resource',
);
/**
* Parses S3 sets via node page
*/
/*
$items['_cals_batch_update_s3_paths_by_node'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_batch_update_s3_paths_by_node',
'file' => "cals_importer.s3paths.inc",
'title' => 'Parse S3 Paths',
);
*/
$items['_cals_importer_update_cors_file_table'] = array(
'access arguments' => array('administer site configuration'),
'page callback' => '_cals_importer_update_cors_file_table',
'file' => "cals_importer.corsS3.inc",
'title' => 'Create attachment from S3 path',
/* 'description' => 'S3 path parsed and attempted to create new file', */
);
return $items;
}
function _cals_importer_block_process_repo_item($form_state) {
if (arg(0) == "node" && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if ($node->type == 'repository_item') {
//$options = array( l("parse record", "node/63268/parse-record") );
$form['nid'] = array(
'#type' => "hidden",
'#default_value' => $nid,
);
$items = _cals_importer_get_block_items();
foreach ($items as $i) {
$cb = $i['page callback'];
$include = TRUE;
if(!user_access($i['access arguments'][0])) $include = FALSE;
if($cb == 'cals_importer_exporter_build_marcxml_from_array' && empty($node->field_xml_stub)) {
//$include = FALSE;
}
if ($include) {
if($cb == 'drupal_get_form') {
$cb = $i['page arguments'][0];
}
$options[$cb] = $i['title'];
$form['op'][$cb] = array(
'#type' => 'submit',
'#id' => $cb,
'#value' => $i['title'],
);
}
}
return $form;
}
}
return;
}
function _cals_importer_block_process_repo_item_submit($form, &$form_state) {
$op = $form_state['values']['op'];
$callback = array_search($op, $form_state['values']);
$nid = $form_state['values']['nid'];
$node = node_load($nid);
$items = _cals_importer_get_block_items();
if (empty($callback)) {
return;
}
else {
$i = $items[$callback];
if (!user_access($i['access arguments'][0])) {
return;
}
//load inc file if exists
if (isset($i['file'])) {
module_load_include('inc', 'cals_importer', str_replace($i['file'], ".inc", ""));
}
if (isset($i['description'])) {
drupal_set_message($i['description']);
}
//printAndDie($callback);
//if (isset())
$callback($node);
}
}
function _cals_importer_update_publisher_and_source_form($options) {
if ( $options['entity_type'] == 'node') {
$vocabulary = taxonomy_vocabulary_machine_name_load('publisher');
$terms = entity_load('taxonomy_term', FALSE, array('vid' => $vocabulary->vid));
//printAndDie($terms);
$options = array();
foreach($terms as $tid => $value) {
//printAndDie($value);
$options[$value->name] = $value->name;
}
//printAndDie($options);
$form = array();
$form['publisher'] = array(
'#type' => 'select',
'#title' => t('Publisher'),
'#description' => t("Please select the Publisher Name."),
'#required' => TRUE,
'#default_value' => '',
'#options' => $options,
);
return $form;
}
}
function _cals_importer_update_publisher_and_source_submit($form, $form_state) {
$return['publisher'] = $form_state['values']['publisher'];
return $return;
}
function _cals_importer_update_publisher_and_source(&$node, $context) {
$publisher = $context['publisher'];
$field_publisher = array();
if(!empty($node->field_publisher)) {
foreach($node->field_publisher[LANGUAGE_NONE] as $k => $v) {
$field_publisher[] = $v['value'];
}
}
$current_publisher = implode(", ", $field_publisher);
//publisher_source
$field_publisher_source = array();
if(!empty($node->field_publisher_source)) {
foreach($node->field_publisher_source[LANGUAGE_NONE] as $k => $v) {
$field_publisher_source[] = $v['value'];
}
}
$current_publisher_source = implode(", ", $field_publisher_source);
if($publisher != $current_publisher && $publisher != $current_publisher_source) {
$node->field_publisher_source[LANGUAGE_NONE] = array();
$node->field_publisher_source[LANGUAGE_NONE][0]['value'] = $current_publisher;
$node->field_publisher[LANGUAGE_NONE] = array();
$node->field_publisher[LANGUAGE_NONE][0]['value'] = $publisher;
node_save($node);
$message = t('Updating Publisher and Publisher Source fields: %title',
array('%title' => $node->title)
);
}
else {
}
//_cals_parse_record_details($node, $fields);
//drupal_set_message($message);
}
/**
* VBO form to update the filename used in the MARC XML generation.
*/
function _cals_importer_generate_marcxml_files_form($options) {
$form = array();
$filename = (is_numeric(arg(1)) && arg(0) == 'node') ? 'nnels_marcxml' . "_" . arg(1) . '.xml' : 'nnels_marcxml,xml';
$form['filename'] = array(
'#type' => 'textfield',
'#title' => t('filename'),
'#description' => t("Please provide a filename."),
'#required' => TRUE,
'#default_value' => $filename,
);
return $form;
}
function _cals_importer_generate_marcxml_files_submit($form, $form_state) {
$return = array();
$return['filename'] = $form_state['values']['filename'];
return $return;
}
function _cals_importer_tab_checker_xmlstub() {
global $user;
if (user_access('view marcxml stub') && arg(0) == 'node') {
$n = node_load(arg(1));
RETURN ($n->type == 'repository_item') ? TRUE : FALSE;
}
return FALSE;
}
function _cals_importer_tab_checker_parse_record() {
global $user;
//todo - change to permission
if (user_access('parse marc records') && arg(0) == 'node') {
$n = node_load(arg(1));
RETURN ($n->type == 'repository_item') ? TRUE : FALSE;
}
return FALSE;
}
function _cals_importer_tab_checker() {
global $user;
//todo - change to permission
if (user_access('parse s3 paths') && arg(0) == 'node') {
$n = node_load(arg(1));
RETURN ($n->type == 'record_set') ? TRUE : FALSE;
}
return FALSE;
}
function _cals_importer_tab_checker_parse_s3_paths() {
global $user;
//todo - change to permission
if (user_access('parse s3 paths') && arg(0) == 'node') {
$n = node_load(arg(1));
RETURN ($n->type == 's3_record_set') ? TRUE : FALSE;
}
return FALSE;
}
function cals_importer_form_alter(&$form, &$form_state, $form_id) {
global $user;
//dpm($form_id);
switch ($form_id) {
case "editableviews_entity_form_marc_tag_crosswalkx":
$fields = field_info_instances("node", "repository_item");
$options = array("" => "--none--");
foreach ($fields as $k => $v) {
$type = $v['widget']['type'];
$label = $v['label'];
//printPre($type, $k, $label);
$options[$k] = "$k ($label)";
}
asort($options);
foreach ($options as $k => $v) {
print $k . "|" . $v . "<br>";
}
printAndDie($options);
//dpm($form['#field_handlers']['node']['field_field_name_drupal_editable']);
foreach ($form['node'] as $nid => $arr) {
//$options = $form['node'][$nid]['field_drupal_field_name']['und']['#options'];
$form['node'][$nid]['field_drupal_field_name']['und']['#options'] = $options;
}
//dpm($form);
break;
case "field_collection_item_formx":
//$form['#submit'][] =
$form['nid'] = array('#type' => 'value', '#default_value' => 9724);
$form['actions']['submit']['#submit'][] = '_cals_importer_s3_cors_field_submit';
//dpm($form);
break;
}
}
function _cals_importer_s3_cors_field_submit($form, &$form_state) {
$filepath = "NO";
if ($form_state['values']['field_s3_to_cors_update'][LANGUAGE_NONE][0]['value'] == 1) {
if (isset($form_state['values']['nid']) && !empty($form_state['values']['field_s3_path'])) {
$node = node_load($form_state['values']['nid']);
$filepath = $form_state['values']['field_s3_path'][LANGUAGE_NONE][0]['value'];
$file = _cals_importer_file_updater($node, $filepath);
}
$form_state['values']['field_s3_file_upload'][LANGUAGE_NONE][0] = (array) $file;