Beispiel #1
0
 function attachments()
 {
     // XXX: cache this
     $att = array();
     $f2p = new File_to_post();
     $f2p->post_id = $this->id;
     if ($f2p->find()) {
         while ($f2p->fetch()) {
             $f = File::staticGet($f2p->file_id);
             if ($f) {
                 $att[] = clone $f;
             }
         }
     }
     return $att;
 }
Beispiel #2
0
 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
 }
Beispiel #3
0
 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);
 }