Revision 56aebcb7
Added by Assos Assos about 8 years ago
drupal7/sites/all/modules/views_data_export/views_data_export.module | ||
---|---|---|
30 | 30 |
); |
31 | 31 |
} |
32 | 32 |
|
33 |
/** |
|
34 |
/** |
|
35 |
* Checks whether the passed URI identifies an export file. |
|
36 |
* |
|
37 |
* @param string $uri |
|
38 |
* A file URI. |
|
39 |
* |
|
40 |
* @return bool |
|
41 |
* TRUE if the URI identifies an export file, FALSE otherwise. |
|
42 |
*/ |
|
43 |
function views_data_export_is_export_file($uri) { |
|
44 |
foreach (entity_load('file', FALSE, array('uri' => $uri)) as $file) { |
|
45 |
// See if this is an export file. |
|
46 |
$usages = file_usage_list($file); |
|
47 |
return !empty($usages['views_data_export']['eid']); |
|
48 |
} |
|
49 |
return FALSE; |
|
50 |
} |
|
51 |
|
|
33 | 52 |
/** |
34 | 53 |
* Implementation of hook_theme(). |
35 | 54 |
*/ |
... | ... | |
114 | 133 |
} |
115 | 134 |
|
116 | 135 |
// We do two things to exports we want to garbage collect |
117 |
// 1. Delete the index table for it, if it is still around |
|
118 |
// 2. Delete the row from the exports table |
|
119 |
// 3. Delete the view from the object_cache |
|
136 |
// 1. Delete the index table for it, if it is still around. |
|
137 |
// 2. Delete the files used during the export. |
|
138 |
// 3. Delete the row from the exports table. |
|
139 |
// 4. Delete the view from the object_cache. |
|
120 | 140 |
if (count($eids_to_clear)) { |
121 | 141 |
foreach ($eids_to_clear as $eid) { |
122 | 142 |
// 1. Delete index table, if it is still around for some reason |
... | ... | |
124 | 144 |
if (db_table_exists($table)) { |
125 | 145 |
db_drop_table($table); |
126 | 146 |
} |
147 |
|
|
148 |
// 2. Delete the files used during the export. |
|
149 |
foreach (views_data_export_export_list_files($eid) as $file) { |
|
150 |
file_delete($file, TRUE); |
|
151 |
} |
|
127 | 152 |
} |
128 | 153 |
|
129 |
// 2. Delete the entries in the exports table.
|
|
154 |
// 3. Delete the entries in the exports table.
|
|
130 | 155 |
db_delete('views_data_export') |
131 | 156 |
->condition('eid', $eids_to_clear, 'IN') |
132 | 157 |
->execute(); |
133 | 158 |
|
134 |
// 3. Clear the cached views
|
|
159 |
// 4. Clear the cached views
|
|
135 | 160 |
views_data_export_view_clear($eids_to_clear); |
136 | 161 |
} |
137 | 162 |
|
... | ... | |
139 | 164 |
} |
140 | 165 |
} |
141 | 166 |
|
167 |
/** |
|
168 |
* Determines where a file is used. |
|
169 |
* |
|
170 |
* @param $eid |
|
171 |
* The ID of a Views Data Export. |
|
172 |
* |
|
173 |
* @return array |
|
174 |
* An array of loaded files objects used by the specified export. |
|
175 |
*/ |
|
176 |
function views_data_export_export_list_files($eid) { |
|
177 |
$result = db_select('file_usage', 'f') |
|
178 |
->fields('f', array('fid')) |
|
179 |
->condition('id', $eid) |
|
180 |
->condition('type', 'eid') |
|
181 |
->condition('module', 'views_data_export') |
|
182 |
->execute(); |
|
183 |
return file_load_multiple($result->fetchCol()); |
|
184 |
} |
|
185 |
|
|
142 | 186 |
|
143 | 187 |
/** |
144 | 188 |
* Batch API callback. |
... | ... | |
268 | 312 |
->condition('eid', $export_id) |
269 | 313 |
->execute(); |
270 | 314 |
} |
271 |
|
|
272 |
/** |
|
273 |
* Implements hook_file_presave(). |
|
274 |
*/ |
|
275 |
function views_data_export_file_presave($file) { |
|
276 |
// Ensure temporary files really are temporary. |
|
277 |
// @see: https://drupal.org/node/2198399 |
|
278 |
if (strpos($file->filename, 'views_data_export') === 0) { |
|
279 |
// There is no FILE_STATUS_TEMPORARY. |
|
280 |
$file->status = 0; |
|
281 |
} |
|
282 |
} |
Also available in: Unified diff
Weekly update of contrib modules