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'; // Visibility "public" is about the FILE MODE, not about the web: this // disk's root is outside the document root and nothing here becomes // reachable by URL. What it changes is 0755/0644 instead of 0700/0600 — // and that is the difference between a document the web process can read // and one it cannot. // // It matters because this command is normally run as root (an artisan // call in a container is root; PHP-FPM is www-data). The first run left // a directory only root could enter, the route's exists() check answered // false, and every link on the page 404'd with nothing in any log to say // why. Storage::disk('local')->put($agreementPath, $renderer->agreement($version), 'public'); Storage::disk('local')->put($measuresPath, $renderer->measures($version), 'public'); $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(), ]); foreach ([$agreementPath, $measuresPath] as $path) { if (Storage::disk('local')->getVisibility($path) !== 'public') { $this->warn("{$path} is not readable by the web process. Run this as the user PHP runs as, or fix the mode — the page will 404 otherwise."); } } $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'; } }