/** * Delete the file and all associated rows (done by foreign keys) and files * $params object should be a json like * <code> * { * 'id': 1 * } * </code> * * @param $params * @return RokCommon_Ajax_Result */ public function delete($params) { $result = new RokCommon_Ajax_Result(); try { RokGallery_Doctrine::getConnection()->beginTransaction(); $file = RokGallery_Model_FileTable::getSingle($params->id); if ($file === false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE_N_TO_DELETE', $params->id)); } $realdirpath = realpath($file->basepath); if ($realdirpath == false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_DIR_N_FOR_FILE_N_TO_REMOVE', $realdirpath, $file->title)); } $delret = RokGallery_Helper::delete_folder($realdirpath); if ($delret === false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_DELETE_DIR_N_FOR_FILE_N_TO_REMOVE', $realdirpath, $file->title)); } $file->delete(); RokGallery_Doctrine::getConnection()->commit(); } catch (Exception $e) { RokGallery_Doctrine::getConnection()->rollback(); throw $e; } return $result; }
/** * Get the full list of jobs * <code> * { * 'ids': [1,2,3] * } * </code> * @param $params * @return RokCommon_Ajax_Result */ public function delete($params) { $result = new RokCommon_Ajax_Result(); try { $q = Doctrine_Query::create()->select('f.*')->from('RokGallery_Model_File f')->whereIn('f.id', $params->ids); $files = $q->execute(array(), Doctrine_Core::HYDRATE_RECORD); $q->free(); try { RokGallery_Doctrine::getConnection()->beginTransaction(); foreach ($files as &$file) { $realdirpath = realpath($file->basepath); if ($realdirpath == false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_DIR_N_FOR_FILE_N_TO_REMOVE', $dirpath, $file->title)); } $delret = RokGallery_Helper::delete_folder($realdirpath); if ($delret === false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_DELETE_DIR_N_FOR_FILE_N_TO_REMOVE', $dirpath, $file->title)); } $file->delete(); } RokGallery_Doctrine::getConnection()->commit(); } catch (Exception $e) { RokGallery_Doctrine::getConnection()->rollback(); throw $e; } } catch (Exception $e) { throw $e; } return $result; }
public static function process() { // process the file delete queue $instance = self::getInstance(); foreach ($instance->get() as $delete_folder) { if (file_exists($delete_folder)) { @RokGallery_Helper::delete_folder($delete_folder); } } $instance->clear(); }