1+ <?php
2+
3+ /**
4+ * Implements hook_install().
5+ */
6+ function cm_crew_connect_install() {
7+
8+ // define path to includes dir because
9+ // some api commands do not return correct
10+ // values during an install
11+ //$logpath = "/var/www/crewconnect-testing.phillycam.org/sites/all/modules/custom/cm_crew_connect/install.log";
12+ // $path_to_drupal = drupal_realpath('cm_crew_connect.install');
13+ $path_to_module = dirname(__FILE__);
14+ $path_to_drupal = getcwd();
15+ //echo "\n";
16+ // $path_to_module = drupal_get_path('module', 'cm_crew_connect');
17+ // $path_to_includes = $path_to_drupal."/".$path_to_module."/includes/";
18+ $path_to_includes = $path_to_module."/includes/";
19+ // echo $path_to_includes;
20+ // create vocabularies
21+ // file_put_contents($logpath, "test: \n", FILE_APPEND);
22+ // file_put_contents($logpath, $path_to_includes."\n", FILE_APPEND);
23+ // file_put_contents($logpath, $path_to_drupal."\n", FILE_APPEND);
24+ // the module requires vocabularies with certain machine names
25+ // for the term reference fields
26+ // so these are hard coded
27+ //
28+ // but the terms can be anything so those are pulled
29+ // from a text file in the module directory
30+ // to allow for pre-install customization
31+
32+ // NOTE: this for now only works with flat vocabularies
33+
34+ cm_crew_connect_vocabulary_create("Crew Connect Position",
35+ "crew_connect_position",
36+ "CMA Crew Connect Module: position taxonomy"
37+ );
38+
39+ cm_crew_connect_vocabulary_create("Crew Connect Opportunity Type",
40+ "crew_connect_opportunity_type",
41+ "CMA Crew Connect Module: opportunity type taxonomy"
42+ );
43+
44+ // load file for Crew Connect Position terms
45+ $crew_connect_position = array_map('str_getcsv', file($path_to_includes.'crew_connect_position.csv'));
46+ // get vid
47+ $crew_connect_position_vid = cm_crew_connect_vid_get("crew_connect_position");
48+ // create terms
49+ foreach ($crew_connect_position as $term) {
50+ cm_crew_connect_term_create($crew_connect_position_vid,$term[0]);
51+ }
52+ $where = drupal_get_path('module', 'cm_crew_connect');
53+ // load file for Crew Connect Position terms
54+ $crew_connect_opportunity_type = array_map('str_getcsv', file($path_to_includes.'crew_connect_opportunity_type.csv'));
55+
56+ //dsm($crew_connect_opportunity_type);
57+ // get vid
58+ $crew_connect_opportunity_type_vid = cm_crew_connect_vid_get("crew_connect_opportunity_type");
59+ // create terms
60+ foreach ($crew_connect_opportunity_type as $term) {
61+ cm_crew_connect_term_create($crew_connect_opportunity_type_vid,$term[0]);
62+ }
63+ //flush caches after taxonomy and term creation
64+ // drupal_flush_all_caches();
65+ //get the contents of the bundle export content type definitions
66+ $bundles = file_get_contents($path_to_includes.'crew-connect-bundle-export.txt');
67+ // setup a form array and call the bundle import submit function
68+ // dsm($bundles);
69+ $form=array();
70+ $form_state=array();
71+ $form_state['values']['macro']=$bundles;
72+ bundle_copy_import_submit($form,$form_state);
73+ //flush caches after content type creation
74+ $result = db_truncate('cache_rules')->execute();
75+ drupal_flush_all_caches();
76+ cache_clear_all();
77+ }
78+
79+
80+ /**
81+ * other helper functions
82+ */
83+
84+ // creates vocabulary
85+ function cm_crew_connect_vocabulary_create($name, $machine_name, $description) {
86+ // Create an empty flat vocabulary with default Drupal 7 fields.
87+ //
88+ $vocabulary = (object) array(
89+ 'name' => $name,
90+ 'machine_name' => $machine_name,
91+ 'description' => $description,
92+ 'hierarchy' => 1,
93+ 'module' => 'taxonomy',
94+ 'weight' => 0,
95+ );
96+
97+ $result = taxonomy_vocabulary_save($vocabulary);
98+ return $result;
99+ }
100+
101+ // returns vid from machine name
102+ function cm_crew_connect_vid_get($machine_name) {
103+ $vocab = taxonomy_vocabulary_machine_name_load($machine_name);
104+ $vid = $vocab->vid;
105+ return $vid;
106+ }
107+
108+ // creates new term
109+ function cm_crew_connect_term_create($vid,$term) {
110+ $newterm = new stdClass();
111+ $newterm->name = $term;
112+ $newterm->vid = $vid;
113+ $newterm->parent = 0; // This tells taxonomy that this is a top-level term
114+ $result = taxonomy_term_save($newterm);
115+ return $result;
116+ }
117+
0 commit comments