Hello,
I have a custom plugin enabled which deletes a row from a database when a file is deleted.
However the file is not deleted anymore from the harddrive, only the row gets deleted from the database. Disabling the plugin and then choose the delete from right click, then the file gets deleted from the harddrive.
Snipped from the code
<?php class PhotoAlbum extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase { function onBeforeExecuteCommand( &$command ) { function buildXml() { $filename = $_POST["files"][0]['name']; $folder = $_POST["files"][0]['folder']; // A "MUST HAVE", CHECKING WHETHER THE CONNECTOR IS ENABLED AND THE BASIC PARAMETERS (LIKE CURRENT FOLDER) ARE SAFE. $this->checkConnector(); $this->checkRequest(); // CHECKING ACL PERMISSIONS, WE'RE JUST GETTING AN INFORMATION ABOUT A FILE, SO FILE_VIEW PERMISSION SEEMS TO BE OK. if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } // MAKE SURE WE ACTUALLY RECEIVED A FILE NAME if (!isset($filename)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); } // IF TYPE = Photoalbums THEN REMOVE FROM DATABASE if ($_GET['type'] == 'Photoalbums') { $delfile = '/ckfinder/userfiles/photoalbums' . $folder . $filename; $result_delete = $this->deleteFromDatabase('/ckfinder/userfiles/photoalbums' . $folder, $filename); // ADDING A <FILESIZE> ELEMENT TO THE XML RESPONSE. $oNode = new Ckfinder_Connector_Utils_XmlNode("Database"); $oNode->addAttribute("action", 'Delete'); $oNode->addAttribute("error", $result_delete['error']); $oNode->addAttribute("errormessage", $result_delete['message']); $oNode->addAttribute("file", $folder . $filename); $this->_connectorNode->addChild($oNode); } else { // ADDING A <database> ELEMENT TO THE XML RESPONSE. $oNode = new Ckfinder_Connector_Utils_XmlNode("Database"); $oNode->addAttribute("message", 'No database action needed'); $this->_connectorNode->addChild($oNode); } } if ( $command == 'DeleteFiles' ) { // THE SENDRESPONSE METHOD IS DEFINED IN XMLCOMMANDHANDLERBASE, IT CREATES // A BASIC XML RESPONSE AND CALLS THE BUILDXML()METHOD $this->sendResponse(); // FALSE = STOP FURTHER EXECUTION. return false; } return true ; } } $photoalbum = new PhotoAlbum(); $config['Hooks']['BeforeExecuteCommand'][] = array($photoalbum, "onBeforeExecuteCommand"); $config['Plugins'][] = 'photoalbums'; ?>
You can see that deleteFromDatabase is called in buildXML, this works.
Responses from with and without plugin enabled is
PLUGIN DISABLED http://localhost:91/ckfinder/core/connector/php/connector.php?command=DeleteFiles&type=Photoalbums& currentFolder=%2FDIRECTORY%2F&langCode=en&hash=f5402535b2f89999&CKFinderCommand=true&files%5B0%5D%5Bfolder%5D=%2FDIRECTORY%2F&files%5B0%5D%5Bname%5D=background1.jpg&files%5B0%5D%5Btype%5D=Photoalbums <?xml version="1.0" encoding="utf-8"?> <Connector resourceType="Photoalbums"> <Error number="0" /> <CurrentFolder path="/DIRECTORY/" url="/ckfinder/userfiles/photoalbums/DIRECTORY/" acl="255" /> <DeleteFiles deleted="1" /> </Connector> PLUGIN ENABLED http://localhost:91/ckfinder/core/connector/php/connector.php?command=DeleteFiles&type=Photoalbums¤tFolder=%2FDIRECTORY%2F&langCode=en &hash=f5402535b2f89999&CKFinderCommand=true&files%5B0%5D%5Bfolder%5D=%2FDIRECTORY%2F&files%5B0%5D%5Bname%5D=background1.jpg&files%5B0%5D%5Btype%5D=Photoalbums <?xml version="1.0" encoding="utf-8"?> <Connector resourceType="Photoalbums"> <Error number="0" /> <CurrentFolder path="/DIRECTORY/" url="/ckfinder/userfiles/photoalbums/DIRECTORY/" acl="255" /> <Database action="Delete" error="" errormessage="No database error" file="/DIRECTORY/background1.jpg" /> </Connector>
However the file is now not deleted from the harddrive.
What am I doing wrong ?
I got a workaround by using
I got a workaround by using Unlink in my code, however I should expect that CKfinder should delete the file and that the hook add functionality.