Example #1
0
    // Decrements reference counter for this file and removes it if it becomes empty.
    function unused()
    {
        if ($this->uses > 1) {
            $this->uses -= 1;
            if ($this->exists and !$this->save()) {
                throw new Error("Cannot save File model of ID [{$this->id}].");
            }
        } else {
            $this->delete();
            is_file($file = $this->file()) and unlink($file);
            Event::fire('file.deleted', $this);
        }
        return $this;
    }
    // Finds other files which MD5 hash is identical to this one.
    //= Query
    function same()
    {
        return static::where('md5', '=', $this->md5);
    }
    function url()
    {
        if ($url = parent::url()) {
            $this->ext and $url .= '.' . $this->ext;
        }
        return $url;
    }
}
File::$table = \Config::get('vanemart::general.table_prefix') . File::$table;