Ejemplo n.º 1
0
 static function getNoticeIDsByFile(File $file)
 {
     $f2p = new File_to_post();
     $f2p->selectAdd();
     $f2p->selectAdd('post_id');
     $f2p->file_id = $file->getID();
     $ids = array();
     if (!$f2p->find()) {
         throw new NoResultException($f2p);
     }
     return $f2p->fetchAll('post_id');
 }
Ejemplo n.º 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
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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);
 }