argument('version'); if (DpaVersion::query()->where('version', $version)->exists()) { $this->error("Version {$version} already exists. Pick another name — two documents under one name makes every acceptance ambiguous."); return self::FAILURE; } $agreementPath = 'dpa/av-vertrag-'.$this->slug($version).'.pdf'; $measuresPath = 'dpa/tom-'.$this->slug($version).'.pdf'; Storage::disk('local')->put($agreementPath, $renderer->agreement($version)); Storage::disk('local')->put($measuresPath, $renderer->measures($version)); $row = DpaVersion::query()->create([ 'version' => $version, 'agreement_path' => $agreementPath, 'measures_path' => $measuresPath, 'note' => 'Aus dem Repository erzeugt (clupilot:publish-dpa).', // Publishing is the point of the command; --draft is for looking at // it first. Every customer who accepted an earlier version is // outstanding again from this moment. 'published_at' => $this->option('draft') ? null : now(), ]); $this->info(($this->option('draft') ? 'Drafted' : 'Published').' version '.$row->version.'.'); $this->line(' '.$agreementPath.' ('.number_format(strlen(Storage::disk('local')->get($agreementPath)) / 1024, 0).' KB)'); $this->line(' '.$measuresPath.' ('.number_format(strlen(Storage::disk('local')->get($measuresPath)) / 1024, 0).' KB)'); return self::SUCCESS; } private function slug(string $version): string { return preg_replace('/[^a-z0-9.-]+/i', '-', $version) ?: 'version'; } }