Version list * ---------------------------------------------------------*/ public function get($args){ //search for the current department in the session and return its versions /** @var meta $depRepo */ $depRepo = Repo::getRepo("meta"); //if no department found, return an empty array return ['versions' => $depRepo->getAllVersions($_SESSION['CurrentDepartmentId']) ]; } /* (5) Remove an existing version for this department * * @version Version name (typically snapshot date) * * @return deleted Whether the version has been deleted * ---------------------------------------------------------*/ public function delete($args){ $version = null; extract($args); /* (1) Dispatch 'deleteVersion' result */ return [ 'deleted' => Repo::getRepo("meta")->deleteVersion($version) ]; } /* (6) Creates a new version (snapshot of database) from now * * @return created_id The created version id (date) * ---------------------------------------------------------*/ public function post($args){ $label = null; extract($args); /* (2) Try to create the snapshot */ try{ /* (2.1) Get database configuration */ $conf = Repo::getDBConfig(); /* (2.2) Try to dump the database */ /** @var Mysqldump*/ $dump = new Mysqldump( 'mysql:host='.$conf['host'].';dbname='.$_SESSION['CurrentDatabase'], $conf['username'], $conf['password'] ); //create temporary file; $file = tmpfile(); //get URI $metaDatas = stream_get_meta_data($file); $tmpFilename = $metaDatas['uri']; //close file pointer fclose($file); //fill the file with sql dump $dump->start($tmpFilename); /** @var department $depRepo */ $depRepo = Repo::getRepo("department"); $dbName = $depRepo->createVersionDatabase($_SESSION['CurrentDepartmentId'],file_get_contents($tmpFilename)); /** @var meta $metaRep */ $metaRep = Repo::getRepo("meta"); $versionId = $metaRep->createVersion($label, $dbName,$_SESSION['CurrentDepartmentId'] ,false); /* (2.5) Return status */ return ['created_id' => $versionId ]; /* (3) On error -> dispatch error */ }catch(\Exception $e){ return ['error' => new Error(Err::RepoError)]; } } /* (6) Modify a version and use it * * * @return bool success * ---------------------------------------------------------*/ public function put($args){ $label = null; $version = null; $default = null; extract($args); /** @var meta $metaRepo */ $metaRepo = Repo::getRepo("meta"); /* (4) Return status */ return [ 'updated' => $metaRepo->updateVersion($version,$label,$default) ]; } }