/** * Resolve a path against a given base path. * * @param AbsolutePathInterface $basePath The base path. * @param PathInterface $path The path to resolve. * * @return AbsolutePathInterface The resolved path. */ public function resolve(AbsolutePathInterface $basePath, PathInterface $path) { if ($path instanceof AbsolutePathInterface) { return $path; } return $basePath->join($path); }
/** * Resolve a path against a given base path. * * @param AbsolutePathInterface $basePath The base path. * @param PathInterface $path The path to resolve. * * @return AbsolutePathInterface The resolved path. */ public function resolve(AbsolutePathInterface $basePath, PathInterface $path) { if ($path instanceof AbsolutePathInterface) { return $path; } if ($path instanceof RelativeWindowsPathInterface) { if ($path->isAnchored()) { return $path->joinDrive($basePath->drive()); } if ($path->hasDrive() && !$path->matchesDrive($basePath->drive())) { return $path->toAbsolute(); } } return $basePath->join($path); }
/** * Helper to initialie the repo. * * @return bool */ protected function initGit() { // Init repo. $this->git = new \derhasi\RedmineToGit\Git(); // @todo: option to init repo. $this->git->setRepository($this->repoPath->string()); // Validate repo, by checking status. try { $this->git->status(); } catch (\PHPGit\Exception\GitException $e) { $this->currentOutput->writeln("<error>{$this->repoPath->string()} is no valid git repo.</error>"); return FALSE; } }
/** * Write representation of the page version to given * * @param \Eloquent\Pathogen\AbsolutePathInterface $base_path * * @return \Eloquent\Pathogen\AbsolutePathInterface[] * Array of path objects that have been changed. */ public function writeFile($base_path) { // Get the wiki file path object relative to the $indexFile = $base_path->resolve(Path::fromString("index.wiki.json")); // Make sure the path exists. $dir = dirname($indexFile->string()); if (!is_dir($dir)) { mkdir($dir, 0777, TRUE); } // Write the json to the index File. $json = json_encode($this, JSON_PRETTY_PRINT); file_put_contents($indexFile->string(), $json); return array($indexFile); }
/** * Normalize the supplied absolute path. * * @param AbsolutePathInterface $path The path to normalize. * * @return AbsolutePathInterface The normalized path. */ protected function normalizeAbsolutePath(AbsolutePathInterface $path) { return $this->factory()->createFromAtoms($this->normalizeAbsolutePathAtoms($path->atoms()), true, false); }
/** * Writes attachments to the local storage. * * @param \Eloquent\Pathogen\AbsolutePathInterface $base_path * @param int $max_file_size * @param \Symfony\Component\Console\Output\OutputInterface $output; * @param \Symfony\Component\Console\Helper\ProgressHelper $progress; * * @return \Eloquent\Pathogen\AbsolutePathInterface[] * Array of path objects */ public function writeAttachments($base_path, $max_file_size, $output, $progress) { $files = array(); // Quit if we got no attachments at all. if (empty($this->attachments)) { return array(); } // First check the files we really need to download. $attachments = array(); $attachments_folder = $base_path->resolve(Path::fromString('attachments')); foreach ($this->attachments as $attachment) { $attachment_local_path = $attachments_folder->resolve(Path::fromString($attachment['id'] . '-' . $attachment['filename'])); // As Redmine cannot change uploaded files, we do not try to download // those again. // Additionally we ignore files that are too big. if (($max_file_size == 0 || $attachment['filesize'] <= $max_file_size) && !file_exists($attachment_local_path->string())) { $attachments[$attachment['content_url']] = $attachment_local_path; } } // Quit of we got no new attachments. if (empty($attachments)) { return array(); } $output->writeln("<comment>Downloading attachments for {$this->title} ...</comment>"); $progress->start($output, count($attachments)); $progress->advance(0); $client = new Client(['base_url' => $this->project->redmine->url, 'defaults' => ['auth' => [$this->project->redmine->apikey, 'password']]]); // Make sure the attachments folder is created. if (!file_exists($attachments_folder->string())) { @mkdir($attachments_folder->string()); } foreach ($attachments as $attachment_url => $attachment_local_path) { $save_stream = Stream::factory(fopen($attachment_local_path->string(), 'w')); $client->get($attachment_url, ['save_to' => $save_stream]); // Add file to the changed files, so they can get commited. $files[] = $attachment_local_path; $progress->advance(); } $progress->finish(); return $files; }