projectsmbhandler.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. include_once DOL_DOCUMENT_ROOT.'/custom/utils/smb/smb.php';
  3. include_once DOL_DOCUMENT_ROOT.'/custom/utils/smb/smbconst.class.php';
  4. include_once DOL_DOCUMENT_ROOT.'/custom/utils/project/projectsmbname.class.php';
  5. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  6. class ProjectSmbHandler
  7. {
  8. public $project;
  9. public $access;
  10. public $directoryStructure;
  11. /**
  12. *
  13. */
  14. public function __construct(Project $project)
  15. {
  16. global $conf;
  17. $this->access = $conf->global->SMB_ACCESS.SmbConst::PATH_SUFFIX;
  18. $this->project = $project;
  19. $this->loadStructure();
  20. }
  21. /**
  22. *
  23. */
  24. private function loadStructure(): void
  25. {
  26. $path = DOL_DOCUMENT_ROOT.'/custom/filesharing/conf/project_dir_structure.json';
  27. if (file_exists($path)) {
  28. if (is_readable($path)) {
  29. $json = file_get_contents($path);
  30. if ($json) {
  31. $this->directoryStructure = json_decode($json);
  32. } else {
  33. dol_syslog('Project directory structure JSON is empty', LOG_INFO);
  34. }
  35. } else {
  36. dol_syslog('Project directory structure JSON not readable', LOG_INFO);
  37. }
  38. } else {
  39. dol_syslog('Project directory structure JSON not exists', LOG_INFO);
  40. }
  41. }
  42. /**
  43. *
  44. */
  45. public function initDirectoryStructure(): void
  46. {
  47. dol_syslog('Init project ('.$this->project->ref.') SMB directory structure', LOG_INFO);
  48. $smb = new smb;
  49. $url = (new ProjectSmbName)->generate($this->project, $this->access);
  50. // string(68) "smb://www-data:Poiu9876@192.168.102.18/project/SMB_TESZT-PJ2402-0045"
  51. $smb->mkdir($url, null, null);
  52. if (!empty($this->directoryStructure)) {
  53. $url = rtrim($url, '/').'/';
  54. foreach ($this->directoryStructure as $dir) {
  55. $smbDirName = $url.str_replace(' ', '_', $dir);
  56. $smb->mkdir($smbDirName, null, null);
  57. //$smb->mkdir($url.$dir, null, null);
  58. }
  59. }
  60. dol_syslog($this->project->ref.' SMB directory structure created', LOG_INFO);
  61. }
  62. }