Commit a9a60abe5b990cd68bfb220faa8a503b722c0f30
1 parent
745c922674
Exists in
master
debug vid
Showing 2 changed files with 35 additions and 0 deletions Side-by-side Diff
sinkronisasi.include.php
... | ... | @@ -158,3 +158,31 @@ function sinkronisasi_export($vocabulary_machine_name) { |
158 | 158 | |
159 | 159 | return $terms; |
160 | 160 | } |
161 | + | |
162 | +function delete_all_terms_by_vid($vid) { | |
163 | + if (!$this->drush()) { | |
164 | + return; | |
165 | + } | |
166 | + | |
167 | + $query = new EntityFieldQuery(); | |
168 | + $query->entityCondition('entity_type', 'taxonomy_term'); | |
169 | + | |
170 | + if (!$vid) { | |
171 | + $this->fatal_error("Unknown vid"); | |
172 | + } | |
173 | + | |
174 | + $query->propertyCondition('vid', $vid); | |
175 | + $result = $query->execute(); | |
176 | + if (!$result) { | |
177 | + return; | |
178 | + } | |
179 | + | |
180 | + foreach ($result['taxonomy_term'] as $term) { | |
181 | + echo "Deleting "; | |
182 | + echo $term->tid; | |
183 | + echo "-> "; | |
184 | + echo taxonomy_term_delete($term->tid); | |
185 | + echo "\n"; | |
186 | + } | |
187 | + | |
188 | +} |
sinkronisasi_import.php
... | ... | @@ -5,6 +5,13 @@ require("sinkronisasi.include.php"); |
5 | 5 | if (function_exists('drush_main')) { |
6 | 6 | $machine_name = "jenis_kantor"; |
7 | 7 | |
8 | + $vocabulary = taxonomy_vocabulary_machine_name_load($machine_name); | |
9 | + | |
10 | + die("a: " . $vocabulary->vid); | |
11 | + | |
12 | + delete_all_terms_by_vid($vodabulary->vid); | |
13 | + | |
14 | + | |
8 | 15 | $data = file_get_contents("adhisimon/sinkronisasi-drupal/$machine_name.txt"); |
9 | 16 | $terms = unserialize($data); |
10 | 17 | sinkronisasi_import($terms); |