/** * @param BaseModel $fileInfo * @return static */ public static function initWithFileMeta(BaseModel $fileInfo) { $instance = new static(); foreach ($fileInfo->toArray() as $k => $v) { $instance->{$k} = $v; } return $instance; }
/** * @param $fid * @return InputFile */ public function decrFileRefCountById($fid) { /** @var static $row */ $row = $this->model->ofId($fid); $row->refCount--; $fileInfo = InputFile::initWithFileMeta($row); if ($row->refCount == 0) { $this->model->deleteById($row->id); } else { $this->model->updateOne($row->id, ['refCount' => $row->refCount]); } return $fileInfo; }
/** * Get chunk content * @param $chunkId string chunk Id * @return string|null */ public function get($chunkId) { $row = $this->model->ofId($chunkId); return $row ? $row['content'] : null; }
/** * @return array */ public function getUsedNodes() { return $this->model->where('fileCount', '>', 0)->get()->toArray(); }