/** * * @param string $rowId * @return boolean */ public function deleteRow($rowId, $callLevel = 1) { // CAUTION: infinite recursion is possible! // Static properties: // $deleteRowFilesToRemove; // array( id =>isImage, ... ) // $deleteRowRowIds; // array( table => array( rowId, ... ), ... ) $wo = WOOOF::$instance; $wo->debug("deleteRow: {$this->tableName} [{$rowId}] [{$callLevel}]"); if ($callLevel == 1) { $this::$deleteRowFilesToRemove = array(); $this::$deleteRowRowIds = array(); } if (isset($this::$deleteRowRowIds[$this->tableName][$rowId])) { $wo->logError(self::_ECP . "0530 deleteRow: Detected cycle on {$this->tableName}.{$rowId}"); return true; // break the cycle } // add to memory $this::$deleteRowRowIds[$this->tableName] = $rowId; $theRow = $this->getRow($rowId); if ($theRow === FALSE) { return FALSE; } if ($theRow === NULL) { $wo->logError(self::_ECP . "0540 Delete row [{$rowId}] not found"); return false; } if ($this->hasDeletedColumn) { $res = $this->dataBase->query('update ' . $this->tableName . ' set isDeleted=\'1\' where id=\'' . WOOOF::$instance->cleanUserInput($rowId) . '\''); if ($res === FALSE) { return FALSE; } } else { if ($this->hasGhostTable) { //TODO: ghost table stuf goes here } // antonis // Handle possible File (externalFiles entries) and Picture fields // Remove any relevant external files as well. for ($i = 0; $i < count($this->columns) / 2; $i++) { $metadata = $this->columns[$i]->getColumnMetaData(); if ($metadata['presentationType'] == WOOOF_columnPresentationTypes::picture or $metadata['presentationType'] == WOOOF_columnPresentationTypes::file) { WOOOF_Util::do_dump($metadata['name']); // add to memory $this::$deleteRowFilesToRemove[] = array($theRow[$metadata['name']], $metadata['presentationType'] == WOOOF_columnPresentationTypes::picture); } // file or image field } // for all columns $res = $this->dataBase->query('delete from ' . $this->tableName . ' where id=\'' . WOOOF::$instance->cleanUserInput($rowId) . '\''); if ($res === FALSE) { return FALSE; } } // antonis // Handle possible Detail records // // CAUTION: tablesGroupedByThis should be the space separated list of all tables with groupedByTable == this.table // CAUTION: this is manually done in dbManager // if ($wo->hasContent($this->tablesGroupedByThis)) { $subTableNames = explode(' ', $this->tablesGroupedByThis); foreach ($subTableNames as $aSubTableName) { $subTable = new WOOOF_dataBaseTable($wo->db, $aSubTableName); if (!$subTable->constructedOk) { return FALSE; } if ($subTable->groupedByTable != $this->tableName) { $wo->logError(self::_ECP . "0550 SubTable name mismatch!"); return FALSE; } $res = $subTable->getResult(array($subTable->localGroupColumn => $rowId), null, null, null, null, true, false); if ($res === FALSE) { return FALSE; } foreach ($subTable->resultRows as $aSubTableRow) { $succ = $subTable->deleteRow($aSubTableRow['id'], $callLevel + 1); if ($succ === FALSE) { return FALSE; } } } // foreach subTable } // there exist sub tables if (isset($this->resultRows[$rowId])) { foreach ($this->resultRows as $key => $value) { if ($value['id'] == $rowId) { unset($this->resultRows[$key]); } } } if ($callLevel == 1) { $wo->debug("deleteRow: Completed for all cases."); foreach ($this::$deleteRowFilesToRemove as $aFileData) { $succ = WOOOF_ExternalFiles::deleteExternalFile($wo, $aFileData[0], $aFileData[1]); // ???ignore false results (like failing to delete row from externaal file. } //debug //echo WOOOF_Util::do_dump($this::$deleteRowFilesToRemove); //echo WOOOF_Util::do_dump($this::$deleteRowRowIds); } return TRUE; }
public function deleteFile($fileAddress, &$productsArray) { if ($this->isAValidAddress($fileAddress, $productsArray, $this->FILE) == TRUE) { $fileRow = $this->db->getRow('__externalFiles', $productsArray['vfsRow']['fileId']); if ($fileRow === FALSE) { $productsArray['errorCode'] = _ECP . '0016'; $productsArray['errorDescription'] = 'File requested could not be extracted from __externalFiles table.'; $this->wo->log(WOOOF_loggingLevels::WOOOF_ERROR, $productsArray['errorCode'] . ' ' . $productsArray['errorDescription']); return FALSE; } elseif (!isset($fileRow['id'])) { $productsArray['errorCode'] = _ECP . '0017'; $productsArray['errorDescription'] = 'File requested could not be found in __externalFiles table.'; $this->wo->log(WOOOF_loggingLevels::WOOOF_ERROR, $productsArray['errorCode'] . ' ' . $productsArray['errorDescription']); return FALSE; } $result = $this->vfsTable->deleteRow($productsArray['arrayPieces'][2]); if ($result === FALSE) { $productsArray['errorCode'] = _ECP . '0018'; $productsArray['errorDescription'] = 'Item deletion failed in __VFS.'; $this->wo->log(WOOOF_loggingLevels::WOOOF_ERROR, $productsArray['errorCode'] . ' ' . $productsArray['errorDescription']); return FALSE; } WOOOF_ExternalFiles::deleteFile($fileRow['id']); $result = unlink($this->wo->getConfigurationFor('absoluteFilesRepositoryPath') . $fileRow['fileName']); if ($result === FALSE) { $productsArray['errorCode'] = _ECP . '0020'; $productsArray['errorDescription'] = 'Item deletion failed from actual file system.'; $this->wo->log(WOOOF_loggingLevels::WOOOF_ERROR, $productsArray['errorCode'] . ' ' . $productsArray['errorDescription']); return FALSE; } $productsArray = array(); return TRUE; } else { return FALSE; } }
<?php require_once '../setup.inc.php'; // TODO: Change the action $requestedAction = 'viewUncontroled'; $pageLocation = '3'; $pageTitle = 'Delete File.'; $wo = new WOOOF(); $pageLocation = '6_' . $wo->cleanUserInput($_GET['location']); $pieces = explode('_', $pageLocation); if (count($pieces) != 4) { die('Malformed file location. Please try again !'); } // antonis ???? The specific field is ignored? $pageLocationTrue = '6_' . $pieces[1] . '_' . $pieces[3]; $permitions = $wo->db->getSecurityPermitionsForLocationAndUser($pageLocationTrue, $userData['id']); //antonis. TODO: Fix and uncomment!!! /* if (!isset($permitions['download']) || $permitions['download']!='1') { die('Security failure: you don\'t have permission to perform the requested action.'); } */ $succ = WOOOF_ExternalFiles::deleteExternalFileByAddress($wo, $pieces[1], $pieces[2], $pieces[3]); if ($succ) { $wo->db->commit(); } else { $wo->db->rollback(); } // TODO: go where ???