コード例 #1
0
ファイル: Syncer.php プロジェクト: codex-project/git-hook
 public function syncRef($ref, $type, Closure $progress = null)
 {
     $this->fire('git.syncer.start', [$ref, $type]);
     $owner = $this->setting('owner');
     $repo = $this->setting('repository');
     $docPath = $this->setting('sync.paths.docs');
     $menuPath = $this->setting('sync.paths.menu');
     $indexPath = $this->setting('sync.paths.index');
     $remote = $this->client($this->setting('remote'));
     $rfs = $remote->getFilesystem($repo, $owner, $ref);
     $files = $rfs->allFiles($this->setting('sync.paths.docs'));
     if (!$rfs->exists($indexPath)) {
         return $this->log('error', 'syncRef could not find the index file', [$indexPath]);
     }
     if (!$rfs->exists($menuPath)) {
         return $this->log('error', 'syncRef could not find the menu file', [$indexPath]);
     }
     $destinationDir = $this->project->path($ref);
     $menuContent = $rfs->get($this->setting('sync.paths.menu'));
     //#base64_decode($menu[ 'content' ]);
     $menuArray = Yaml::parse($menuContent);
     $unfilteredPages = [];
     $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
     $this->ensureDirectory($destinationDir);
     $files = $rfs->allFiles($this->setting('sync.paths.docs'));
     $total = count($files);
     $syncer = $this;
     foreach ($files as $current => $file) {
         $localPath = Path::makeRelative($file, $this->setting('sync.paths.docs'));
         if ($progress instanceof Closure) {
             #$file = new \SplFileInfo(path_join($this->project->getPath(), $destinationDir, $localPath));
             $this->project->getContainer()->call($progress, compact('current', 'total', 'file', 'files', 'syncer'));
         }
         $localPath = Path::join($destinationDir, $localPath);
         $dir = Path::getDirectory($localPath);
         $this->ensureDirectory($dir);
         $this->files->put($localPath, $rfs->get($file));
     }
     // index.md resolving
     $indexFile = $rfs->get($this->setting('sync.paths.index'));
     $this->files->put(Path::join($destinationDir, 'index.md'), $indexFile);
     if ($type === 'branch') {
         $branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner'));
         $this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']);
     }
     $this->fire('git.syncer.finish', [$ref, $type]);
 }
コード例 #2
0
ファイル: Syncer.php プロジェクト: docit/git-hook
 public function syncRef($ref, $type)
 {
     $this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.start', compact('ref', 'type'));
     $this->runHook('git:syncer:start', [$this, $ref, $type]);
     $owner = $this->setting('owner');
     $repo = $this->setting('repository');
     $docPath = $this->setting('sync.paths.docs');
     $indexPath = $this->setting('sync.paths.docs');
     $remote = $this->client($this->setting('remote'));
     $rfs = $remote->getFilesystem($repo, $owner, $ref);
     $files = $rfs->allFiles($this->setting('sync.paths.docs'));
     $indexExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'index.md'));
     $menuExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'menu.yml'));
     $a = 'b';
     if (!$indexExists || !$menuExists) {
         return;
     }
     $destinationDir = Path::join($this->project->getPath(), $ref);
     $menuContent = $rfs->get($this->setting('sync.paths.menu'));
     //#base64_decode($menu[ 'content' ]);
     $menuArray = Yaml::parse($menuContent);
     $unfilteredPages = [];
     $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
     $this->ensureDirectory($destinationDir);
     foreach ($rfs->allFiles($this->setting('sync.paths.docs')) as $path) {
         $localPath = Path::makeRelative($path, $this->setting('sync.paths.docs'));
         $localPath = Path::join($destinationDir, $localPath);
         $dir = Path::getDirectory($localPath);
         $this->ensureDirectory($dir);
         $this->files->put($localPath, $rfs->get($path));
     }
     if ($type === 'branch') {
         $branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner'));
         $this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']);
     }
     $this->runHook('git:syncer:done', [$this, $ref, $type]);
     $this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.end', compact('ref', 'type'));
 }