public function filedepot::deleteNodeCCKField in filedepot 6
2 calls to filedepot::deleteNodeCCKField()
File
- ./
filedepot.class.php, line 644 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function deleteNodeCCKField($cid, $cckfid) {
// Need to update Drupal and have it remove the files record and CCK related table record (if any the folder (node) has any attachments)
$nid = db_result(db_query("SELECT nid FROM {filedepot_categories} WHERE cid=%d", $cid));
$node = node_load($nid);
if (is_array($node->field_filedepot_file) and count($node->field_filedepot_file) > 0) {
foreach ($node->field_filedepot_file as $id => $file) {
if ($file['fid'] == $cckfid) {
/* Was having an issue doing a multi-delete which appeared to be cache related.
* After the file was deleted the next delete when the node was loaded would still contain the un-deleted file reference
* And the nodeapi hook would then treat it as a missing filedepot record - like a new file was added from the drupal UI
* and add the file back - but not all the cck data was there anymore.
* Test: Add three files to a folder, delete 2 and then add 1 more new file
* Doing single deletes worked using the method to unset files array data for the attachment (file)
* to remove and then calling the node_save. I have opted for now to delete the cck data directly.
* Need to investigate the cache clear options
* cache_clear('content_type_info') or content_clear_type_cache()
*
*/
//unset($node->field_filedepot_file[$id]);
//node_save($node);
db_query("DELETE FROM {files} WHERE fid = %d", $cckfid);
// Remove the record from the drupal files table
db_query("DELETE FROM {content_field_filedepot_file} WHERE vid = %d AND field_filedepot_file_fid = %d", $nid, $cckfid);
// Adding this function to clear CCK cache appears to have fixed the delete issue.
content_clear_type_cache();
}
}
}
}