/** * ファイル削除 * * @param Model $Model モデル * @param array $data received post data * @param string $alias 登録するモデル名 * @param string $fileIdColom ファイルIDのDBカラム名 * @param int $index File inputのindex * @return mixed Array on success, false on error * @throws InternalErrorException */ public function deleteFile(Model $Model, $data, $alias, $fileIdColom, $index = 0) { if (isset($data['DeleteFile'][$index]['File']['id']) && $data['DeleteFile'][$index]['File']['id'] > 0) { //データ削除 if (!$Model->FileModel->deleteAll([$Model->FileModel->alias . '.id' => $data['DeleteFile'][$index]['File']['id']], true, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } if (!$Model->FileModel->deleteFileAssociated($data['DeleteFile'][$index]['File']['id'])) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } // 暫定対応(;'∀') コメントアウトする。 // 現在、path=フォルダなので、フォルダ削除になっている。2ファイルを1度にアップロードすると同じフォルダにアップロードされる。 // 更新時に1ファイルだけアップロードすると、下記フォルダ削除によりもう一方のファイルが消える問題あり。 // // 1ファイルのアップロード毎にフォルダが別になれば、下記フォルダ削除のままでも問題解消する。 //ファイル削除 //$folder = new Folder(); //$folder->delete($data['DeleteFile'][$index]['File']['path']); // サムネイルだったら、個別に削除したので、現在のままでも大丈夫 // ファイル削除 $file = new File($data['DeleteFile'][$index]['File']['path'] . $data['DeleteFile'][$index]['File']['name']); $file->delete(); // サムネイル削除 $this->__deleteThumbnail($data['DeleteFile'][$index]['File'], 'url_big'); $this->__deleteThumbnail($data['DeleteFile'][$index]['File'], 'url_medium'); $this->__deleteThumbnail($data['DeleteFile'][$index]['File'], 'url_small'); $this->__deleteThumbnail($data['DeleteFile'][$index]['File'], 'url_thumbnail'); // 空ならアップロードディレクトリ削除 $folder = new Folder($data['DeleteFile'][$index]['File']['path']); if ($folder->dirsize() === 0) { $folder->delete(); } $data[$alias][$fileIdColom] = 0; } return $data; }
private function __advancedFolderFind($conditions) { if (empty($this->fileList[0])) { $this->return = array(); return true; } $i = 0; foreach ($this->fileList[0] as $folder) { if (in_array($folder, $this->ignore)) { continue; } if ($this->recursive > -2) { $Folder = new Folder($this->path . DS . $folder); $this->return[$i]['Folder']['path'] = $Folder->path; $this->return[$i]['Folder']['name'] = basename($this->return[$i]['Folder']['path']); $this->return[$i]['Folder']['parent'] = dirname($this->return[$i]['Folder']['path']); $this->return[$i]['Folder']['relative'] = $this->__relativePath($this->return[$i]['Folder']['path']); $stat = stat($this->return[$i]['Folder']['path']); $this->__fileStatus($i, $stat); if ($this->recursive > -1) { $this->return[$i]['Folder']['accessed'] = date('Y-m-d H:i:s', $stat['atime']); $this->return[$i]['Folder']['modified'] = date('Y-m-d H:i:s', $stat['mtime']); $this->return[$i]['Folder']['created'] = date('Y-m-d H:i:s', $stat['ctime']); if ($this->recursive > 0) { $this->return[$i]['Folder']['size'] = $Folder->dirsize(); $this->return[$i]['Folder']['absolute'] = $Folder->isAbsolute($this->return[$i]['Folder']['path']); $children = $Folder->tree($this->return[$i]['Folder']['path']); $this->return[$i]['Folder']['sub_folders'] = count($children[0]) - 1; $this->return[$i]['Folder']['sub_files'] = count($children[1]); if ($this->recursive > 1) { $this->return[$i]['Folder']['realpath'] = $Folder->realpath($this->return[$i]['Folder']['path']); $this->return[$i]['Folder']['windows'] = $Folder->isWindowsPath($this->return[$i]['Folder']['path']); $this->return[$i]['Folder']['Children'] = $children; $this->return[$i]['Folder']['Extended'] = $stat; $i++; continue; } $i++; } $i++; } $i++; } $i++; } return true; }
public function edp($id = null) { $this->loadModel('User'); $users = $this->User->find('count', array('conditions' => array('User.publish' => 1, 'User.soft_delete' => 0), 'recursive' => -1)); $this->set('countUsers', $users); $this->loadModel('ListOfComputer'); $listofcomps = $this->ListOfComputer->find('count', array('conditions' => array('ListOfComputer.publish' => 1, 'ListOfComputer.soft_delete' => 0), 'recursive' => -1)); $this->set('countListofcomps', $listofcomps); $this->loadModel('DatabackupLogbook'); $countDataBakupLogbk = $this->DatabackupLogbook->find('count', array('conditions' => array('DatabackupLogbook.publish' => 1, 'DatabackupLogbook.soft_delete' => 0), 'recursive' => -1)); $this->set('countDataBakupLogbk', $countDataBakupLogbk); $this->loadModel('ListOfSoftware'); $listOfSofts = $this->ListOfSoftware->find('count', array('conditions' => array('ListOfSoftware.publish' => 1, 'ListOfSoftware.soft_delete' => 0), 'recursive' => -1)); $this->set('countListOfSofts', $listOfSofts); $this->loadModel('ListOfComputerListOfSoftware'); $listOfCompSofts = $this->ListOfComputerListOfSoftware->find('count', array('conditions' => array('ListOfComputerListOfSoftware.publish' => 1, 'ListOfComputerListOfSoftware.soft_delete' => 0), 'recursive' => -1)); $this->set('countListOfCompSofts', $listOfCompSofts); $this->loadModel('UsernamePasswordDetail'); $usrPassDetails = $this->UsernamePasswordDetail->find('count', array('conditions' => array('UsernamePasswordDetail.publish' => 1, 'UsernamePasswordDetail.soft_delete' => 0), 'recursive' => -1)); $this->set('countUsrPassDetails', $usrPassDetails); $this->loadModel('DailyBackupDetail'); $this->loadModel('DatabackupLogbook'); if ($this->request->is('post')) { foreach ($this->request->data['DatabackupLogbook'] as $databackupLogbook) { if (!empty($databackupLogbook['id']) && (isset($databackupLogbook['task_performed']) || isset($databackupLogbook['comments']))) { $databackupLogbook['backup_date'] = date('Y-m-d'); $databackupLogbook['employee_id'] = $this->Session->read('User.employee_id'); $databackupLogbook['branchid'] = $this->Session->read('User.branch_id'); $databackupLogbook['publish'] = 1; $databackupLogbook['departmentid'] = $this->Session->read('User.department_id'); $databackupLogbook['modified_by'] = $this->Session->read('User.id'); $this->DatabackupLogbook->save($databackupLogbook, false); } else { if (empty($databackupLogbook['id']) && isset($databackupLogbook['task_performed']) && $databackupLogbook['task_performed'] > 0) { $this->DatabackupLogbook->create(); $databackupLogbook['backup_date'] = date('Y-m-d'); $databackupLogbook['employee_id'] = $this->Session->read('User.employee_id'); $databackupLogbook['branchid'] = $this->Session->read('User.branch_id'); $databackupLogbook['departmentid'] = $this->Session->read('User.department_id'); $databackupLogbook['created_by'] = $this->Session->read('User.id'); $databackupLogbook['modified_by'] = $this->Session->read('User.id'); $databackupLogbook['publish'] = 1; $this->DatabackupLogbook->save($databackupLogbook, false); } } } $this->Session->setFlash(__('The Backup Details has been saved')); $this->redirect(array('action' => 'edp')); } $onlyBranch = null; $onlyOwn = null; $condition1 = null; $condition2 = null; $condition3 = null; if ($this->Session->read('User.is_mr') == 0 && $branchIDYes == true) { $onlyBranch = array('DailyBackupDetail.branch_id' => $this->Session->read('User.branch_id')); } if ($this->Session->read('User.is_view_all') == 0) { $onlyOwn = array('DailyBackupDetail.created_by' => $this->Session->read('User.id')); } if ($this->Session->read('User.is_mr') == 0) { $condition3 = array('DailyBackupDetail.employee_id' => $this->Session->read('User.employee_id')); } $finalCond = array('OR' => array($onlyBranch, $onlyOwn, $condition3)); if ($this->request->params['named']) { if ($this->request->params['named']['published'] == null) { $condition1 = null; } else { $condition1 = array('DailyBackupDetail.publish' => $this->request->params['named']['published']); } if ($this->request->params['named']['soft_delete'] == null) { $condition2 = null; } else { $condition2 = array('DailyBackupDetail.soft_delete' => $this->request->params['named']['soft_delete']); } if ($this->request->params['named']['soft_delete'] == null) { $conditions = array($onlyBranch, $onlyOwn, $condition1, $condition3, 'DailyBackupDetail.soft_delete' => 0); } else { $conditions = array($condition1, $condition2, $finalCond); } } else { $conditions = array($finalCond, 'DailyBackupDetail.soft_delete' => 0); } $options = array('order' => array('DailyBackupDetail.sr_no' => 'DESC'), 'conditions' => array($conditions)); $this->DailyBackupDetail->recursive = 0; $dailyBackupDetails = $this->DailyBackupDetail->find('all', $options); $this->loadModel('Schedule'); $scheduleList = $this->Schedule->find('list', array('conditions' => array('Schedule.publish' => 1, 'Schedule.soft_delete' => 0), 'recursive' => -1)); foreach ($dailyBackupDetails as $key => $dailyBackupDetail) { $test = $this->DatabackupLogbook->find('first', array('order' => array('DatabackupLogbook.sr_no' => 'DESC'), 'conditions' => array('DatabackupLogbook.daily_backup_detail_id' => $dailyBackupDetail['DailyBackupDetail']['id'], 'DatabackupLogbook.employee_id' => $dailyBackupDetail['DailyBackupDetail']['employee_id']), 'recursive' => -1)); $listOfComp = $this->ListOfComputer->find('first', array('conditions' => array('ListOfComputer.id' => $dailyBackupDetail['DailyBackupDetail']['list_of_computer_id']), 'fields' => array('make'), 'recursive' => -1)); $dailyBackupDetails[$key]['DataBackUp']['ScheduleName'] = $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']]; if (count($test)) { if ($scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'dailly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Dailly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'daily' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Daily') { if (date('Y-m-d', strtotime($test['DatabackupLogbook']['created'])) == date('Y-m-d')) { $dailyBackupDetails[$key]['DatabackupLogbook'] = $test['DatabackupLogbook']; } else { $dailyBackupDetails[$key]['DatabackupLogbook'] = array(); } } else { if ($scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'weekly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Weekly') { if (date('W', strtotime($test['DatabackupLogbook']['created'])) == date('W')) { $dailyBackupDetails[$key]['DatabackupLogbook'] = $test['DatabackupLogbook']; } else { $dailyBackupDetails[$key]['DatabackupLogbook'] = array(); } } else { if ($scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'monthly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Monthly') { if (date('m', strtotime($test['DatabackupLogbook']['created'])) == date('m')) { $dailyBackupDetails[$key]['DatabackupLogbook'] = $test['DatabackupLogbook']; } else { $dailyBackupDetails[$key]['DatabackupLogbook'] = array(); } } else { if ($scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'quarterly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Quarterly') { $created = date('Y-m-d', strtotime($dailyBackupDetail['DailyBackupDetail']['created'])); $currentDate = date('Y-m-d', strtotime($dailyBackupDetail['DailyBackupDetail']['created'])); $lastQuarter = date('Y-m-d'); $nextQuarter = date('Y-m-d'); $dateArray = array(); $i = 0; while ($currentDate <= $lastQuarter) { $nextQuarter = date('Y-m-d', strtotime('+3 month', strtotime($currentDate))); $dateArray[$i]['currentDate'] = $currentDate; $dateArray[$i]['nextQuarter'] = $nextQuarter; $currentDate = $nextQuarter; $i++; } $count = count($dateArray); if (date('Y-m-d', strtotime($test['DatabackupLogbook']['created'])) >= $dateArray[$count - 1]['currentDate'] && date('Y-m-d', strtotime($test['DatabackupLogbook']['created'])) <= $dateArray[$count - 1]['nextQuarter']) { $dailyBackupDetails[$key]['DatabackupLogbook'] = $test['DatabackupLogbook']; } else { $dailyBackupDetails[$key]['DatabackupLogbook'] = array(); } } else { if ($scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'yearly' || $scheduleList[$dailyBackupDetail['DataBackUp']['schedule_id']] == 'Yearly') { if (date('y', strtotime($test['DatabackupLogbook']['created'])) == date('y')) { $dailyBackupDetails[$key]['DatabackupLogbook'] = $test['DatabackupLogbook']; } else { $dailyBackupDetails[$key]['DatabackupLogbook'] = array(); } } } } } } } if (count($listOfComp)) { $dailyBackupDetails[$key]['DatabackupLogbook']['make'] = $listOfComp['ListOfComputer']['make']; } } $this->set('dailyBackupDetails', $dailyBackupDetails); $this->set('editId', $id); //get folder details : $folder = new Folder(APP . DS . 'webroot/files/'); $folderSize = $folder->dirsize(); $dbSize = $this->_getDbSize(); $this->set(array('dbSize' => $this->_format_file_size($dbSize), 'folderSize' => $this->_format_file_size($folderSize), 'totalSize' => $this->_format_file_size($dbSize + $folderSize))); }