12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- global $_,$conf;
- switch($_['action']){
- case 'hackpoint_resource_git_save':
- Action::write(function(&$response){
- global $myUser,$_;
- require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Sketch.class.php');
- require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Resource.class.php');
- require_once(__DIR__.SLASH.'GitRepository.class.php');
- $item = Resource::provide('id',1);
- $sketch = $item->join('sketch');
-
- if($sketch->creator != $myUser->login) throw new Exception("Permissions insuffisantes",403);
- $repository = GitRepository::provide('repository');
- $repository->url = $_['url'];
- $repository->synchronise = $_['synchronise'] =='true';
- $repository->save();
- $item->content = $repository->id;
- $item->save();
- $response['repository'] = $repository->id;
- });
- break;
-
- case 'hackpoint_resource_git_explore':
- Action::write(function(&$response){
- global $myUser,$_;
-
-
- require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Sketch.class.php');
- require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Resource.class.php');
- require_once(__DIR__.SLASH.'..'.SLASH.'document'.SLASH.'Element.class.php');
- require_once(__DIR__.SLASH.'GitRepository.class.php');
- $resource = Resource::getById($_['id']);
- $repository = GitRepository::getById($resource->content);
- $parentDir = dirname($repository->directory());
- $gitDir = basename($repository->directory());
-
- if(!file_exists($parentDir)) mkdir($parentDir,0755,true);
-
- system('cd "'.$parentDir.'" && git clone '.$repository->url.' '.$gitDir);
-
-
- $response['root'] = str_replace(array(Element::root(),'\\'),array('','/'),$repository->directory());
- });
- break;
-
- }
- ?>
|