fixed data path issue
This commit is contained in:
parent
eb50f184b3
commit
679c123930
2 changed files with 23 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ dist
|
||||||
/logs/
|
/logs/
|
||||||
/.idea/
|
/.idea/
|
||||||
/vendor/
|
/vendor/
|
||||||
|
/data/
|
||||||
|
|
|
@ -239,20 +239,29 @@ class Pulsebridge
|
||||||
*
|
*
|
||||||
* @return bool true on success, false if folder is not available
|
* @return bool true on success, false if folder is not available
|
||||||
*/
|
*/
|
||||||
public function setDataPath(
|
public function setDataPath($dataPath)
|
||||||
$data_path
|
{
|
||||||
) {
|
// Ensure the path ends with DIRECTORY_SEPARATOR
|
||||||
if (file_exists($data_path)) {
|
if (substr($dataPath, -strlen(DIRECTORY_SEPARATOR)) !== DIRECTORY_SEPARATOR) {
|
||||||
if (substr($data_path, -strlen(DIRECTORY_SEPARATOR)) != DIRECTORY_SEPARATOR) {
|
$dataPath .= DIRECTORY_SEPARATOR;
|
||||||
$data_path.= DIRECTORY_SEPARATOR;
|
|
||||||
}
|
}
|
||||||
$this->DataPath = $data_path;
|
|
||||||
return true;
|
// Check if the data folder exists, and create it if not
|
||||||
} else {
|
if (!file_exists($dataPath) || !is_dir($dataPath)) {
|
||||||
return false;
|
// Create the data folder with 0755 permissions (you can adjust this based on your needs)
|
||||||
|
mkdir($dataPath, 0755, true);
|
||||||
|
|
||||||
|
// Check if the folder creation was successful
|
||||||
|
if (!file_exists($dataPath) || !is_dir($dataPath)) {
|
||||||
|
throw new \RuntimeException("Failed to create data folder: $dataPath");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the data path
|
||||||
|
$this->DataPath = $dataPath;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get the flat-file data path
|
* Get the flat-file data path
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue