action.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. global $_,$conf;
  3. switch($_['action']){
  4. case 'hackpoint_resource_git_save':
  5. Action::write(function(&$response){
  6. global $myUser,$_;
  7. require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Sketch.class.php');
  8. require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Resource.class.php');
  9. require_once(__DIR__.SLASH.'GitRepository.class.php');
  10. $item = Resource::provide('id',1);
  11. $sketch = $item->join('sketch');
  12. if($sketch->creator != $myUser->login) throw new Exception("Permissions insuffisantes",403);
  13. $repository = GitRepository::provide('repository');
  14. $repository->url = $_['url'];
  15. $repository->synchronise = $_['synchronise'] =='true';
  16. $repository->save();
  17. $item->content = $repository->id;
  18. $item->save();
  19. $response['repository'] = $repository->id;
  20. });
  21. break;
  22. case 'hackpoint_resource_git_explore':
  23. Action::write(function(&$response){
  24. global $myUser,$_;
  25. require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Sketch.class.php');
  26. require_once(__DIR__.SLASH.'..'.SLASH.'hackpoint'.SLASH.'Resource.class.php');
  27. require_once(__DIR__.SLASH.'..'.SLASH.'document'.SLASH.'Element.class.php');
  28. require_once(__DIR__.SLASH.'GitRepository.class.php');
  29. $resource = Resource::getById($_['id']);
  30. $repository = GitRepository::getById($resource->content);
  31. $parentDir = dirname($repository->directory());
  32. $gitDir = basename($repository->directory());
  33. if(!file_exists($parentDir)) mkdir($parentDir,0755,true);
  34. system('cd "'.$parentDir.'" && git clone '.$repository->url.' '.$gitDir);
  35. $response['root'] = str_replace(array(Element::root(),'\\'),array('','/'),$repository->directory());
  36. });
  37. break;
  38. }
  39. ?>