function clearFiles() { $f2p = new File_to_post(); $f2p->post_id = $this->id; if ($f2p->find()) { while ($f2p->fetch()) { $f2p->delete(); } } // FIXME: decide whether to delete File objects // ...and related (actual) files }
public function delete($useWhere = false) { // Delete the file, if it exists locally if (!empty($this->filename) && file_exists(self::path($this->filename))) { $deleted = @unlink(self::path($this->filename)); if (!$deleted) { common_log(LOG_ERR, sprintf('Could not unlink existing file: "%s"', self::path($this->filename))); } } // Clear out related things in the database and filesystem, such as thumbnails if (Event::handle('FileDeleteRelated', array($this))) { $thumbs = new File_thumbnail(); $thumbs->file_id = $this->id; if ($thumbs->find()) { while ($thumbs->fetch()) { $thumbs->delete(); } } $f2p = new File_to_post(); $f2p->file_id = $this->id; if ($f2p->find()) { while ($f2p->fetch()) { $f2p->delete(); } } } // And finally remove the entry from the database return parent::delete($useWhere); }