| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- include_once DOL_DOCUMENT_ROOT.'/custom/utils/smb/smb.php';
- include_once DOL_DOCUMENT_ROOT.'/custom/utils/smb/smbconst.class.php';
- include_once DOL_DOCUMENT_ROOT.'/custom/utils/project/projectsmbname.class.php';
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- class ProjectSmbHandler
- {
- public $project;
- public $access;
- public $directoryStructure;
- /**
- *
- */
- public function __construct(Project $project)
- {
- global $conf;
- $this->access = $conf->global->SMB_ACCESS.SmbConst::PATH_SUFFIX;
- $this->project = $project;
- $this->loadStructure();
- }
- /**
- *
- */
- private function loadStructure(): void
- {
- $path = DOL_DOCUMENT_ROOT.'/custom/filesharing/conf/project_dir_structure.json';
-
- if (file_exists($path)) {
- if (is_readable($path)) {
- $json = file_get_contents($path);
- if ($json) {
- $this->directoryStructure = json_decode($json);
- } else {
- dol_syslog('Project directory structure JSON is empty', LOG_INFO);
- }
- } else {
- dol_syslog('Project directory structure JSON not readable', LOG_INFO);
- }
- } else {
- dol_syslog('Project directory structure JSON not exists', LOG_INFO);
- }
- }
- /**
- *
- */
- public function initDirectoryStructure(): void
- {
- dol_syslog('Init project ('.$this->project->ref.') SMB directory structure', LOG_INFO);
- $smb = new smb;
- $url = (new ProjectSmbName)->generate($this->project, $this->access);
- // string(68) "smb://www-data:Poiu9876@192.168.102.18/project/SMB_TESZT-PJ2402-0045"
- $smb->mkdir($url, null, null);
- if (!empty($this->directoryStructure)) {
- $url = rtrim($url, '/').'/';
- foreach ($this->directoryStructure as $dir) {
- $smbDirName = $url.str_replace(' ', '_', $dir);
- $smb->mkdir($smbDirName, null, null);
- //$smb->mkdir($url.$dir, null, null);
- }
- }
- dol_syslog($this->project->ref.' SMB directory structure created', LOG_INFO);
- }
- }
|