public function beforeDelete(Event $event, Entity $entity) { $upload_root_offset = Configure::read('UPLOAD_ROOT_OFFSET'); $upload_root = Configure::read('UPLOAD_ROOT'); $id = $entity->id; $job_id = $entity->job_id; // delete creative folder and all its contents AppController::delete_folder($upload_root_offset . DS . $upload_root . DS . $job_id . DS . $id); /* $Files = TableRegistry::get('Files'); $files = $Files->find('all',['conditions'=>['creative_id'=>$id]])->toArray(); if( !empty($files) ) { foreach($files as $row){ $file_path = $upload_root_offset . $row['file']; if( file_exists($file_path) ) { if ( is_dir($file_path) ){ if( AppController::delete_folder($file_path) ) { } } else if( unlink($file_path) ) { } } } } */ }
public function beforeDelete(Event $event, Entity $entity) { $upload_root_offset = Configure::read('UPLOAD_ROOT_OFFSET'); $file_path = $upload_root_offset . $entity->file; if ($entity->archived === 1) { $file_path = $upload_root_offset . dirname($entity->file) . DS . Configure::read('UPLOAD_VERSION_DIR') . DS . 'v_' . $entity->version . '_' . basename($file_path); } if ($entity->version_id) { $Files = TableRegistry::get('Files'); // delete versions record if this was the only file left in the group //echo 'count:'.$Files->find('all')->where(['version_id'=>$entity->version_id])->count(); if ($Files->find('all')->where(['version_id' => $entity->version_id])->count() <= 1) { $Versions = TableRegistry::get('Versions'); if ($version = $Versions->get($entity->version_id)) { $Versions->delete($version); } } } if (file_exists($file_path) && $file_path !== Configure::read("UPLOAD_ROOT")) { if (is_dir($file_path)) { if (AppController::delete_folder($file_path)) { //return true; } } else { if (unlink($file_path)) { //echo 'file - '.$file_path.' - deleted'; //return true; } } } return true; }
public function beforeDelete(Event $event, Entity $entity) { $root = Configure::read('UPLOAD_ROOT_OFFSET') . Configure::read('UPLOAD_ROOT'); $file_path = $root . DS . $entity->id; if (file_exists($file_path) && $entity->id) { if (is_dir($file_path)) { if (AppController::delete_folder($file_path)) { return true; } } else { if (unlink($file_path)) { return true; } } } return true; }
public function page_exit() { $this->layout = null; $this->render(false); $Files = TableRegistry::get('Files'); // delete files in limbo $files = $Files->find('all', ['conditions' => ["committed" => 0, "user_id" => $this->request->data['user_id']]])->toArray(); if (!empty($files)) { foreach ($files as $file) { $file_path = $file['file']; if ($file_path === $this->upload_root) { return false; } $id = $file['id']; if (file_exists($this->upload_root_offset . $file_path)) { if (is_dir($this->upload_root_offset . $file_path)) { if (AppController::delete_folder($this->upload_root_offset . $file_path)) { if ($Files->delete($Files->get($id))) { //die(json_encode(array("status"=>"success","file"=>$file['Files']))); } } } else { if (unlink($this->upload_root_offset . $file_path)) { if ($Files->delete($Files->get($id))) { //die( json_encode(array("status"=>"success","file"=>$file['Files'])) ); } } } } } } }