Commit cbc7f085 authored by Manfred Kutas's avatar Manfred Kutas

ZP-1261 Added parameter for getStateFiles() as glob() pattern.

Released under the Affero GNU General Public License (AGPL) version 3.
parent a0faf495
...@@ -35,6 +35,8 @@ class FileStateMachine implements IStateMachine { ...@@ -35,6 +35,8 @@ class FileStateMachine implements IStateMachine {
private $settingsfilename; private $settingsfilename;
private $statefiles; // List of the state files. Used by z-push-admin and scripts. private $statefiles; // List of the state files. Used by z-push-admin and scripts.
private $devicedatafiles; // List of the device data files. Used by z-push-admin and scripts. private $devicedatafiles; // List of the device data files. Used by z-push-admin and scripts.
private $pattern; // State patter for glob()
/** /**
* Constructor * Constructor
* *
...@@ -63,6 +65,7 @@ class FileStateMachine implements IStateMachine { ...@@ -63,6 +65,7 @@ class FileStateMachine implements IStateMachine {
$this->statefiles = array(); $this->statefiles = array();
$this->devicedatafiles = array(); $this->devicedatafiles = array();
$this->pattern = STATE_DIR.'*/*/*';
} }
/** /**
...@@ -164,8 +167,7 @@ class FileStateMachine implements IStateMachine { ...@@ -164,8 +167,7 @@ class FileStateMachine implements IStateMachine {
* @throws StateInvalidException * @throws StateInvalidException
*/ */
public function CleanStates($devid, $type, $key, $counter = false, $thisCounterOnly = false) { public function CleanStates($devid, $type, $key, $counter = false, $thisCounterOnly = false) {
$filePath = $this->getFullFilePath($devid, $type, $key); $matching_files = $this->getStateFiles($this->getFullFilePath($devid, $type, $key). "*");
$matching_files = array_filter($this->getStateFiles(), function($var) use ($filePath) {return strpos($var, $filePath) !== false;});
if (is_array($matching_files)) { if (is_array($matching_files)) {
foreach($matching_files as $state) { foreach($matching_files as $state) {
$file = false; $file = false;
...@@ -490,12 +492,15 @@ class FileStateMachine implements IStateMachine { ...@@ -490,12 +492,15 @@ class FileStateMachine implements IStateMachine {
/** /**
* Returns the list of the state files. * Returns the list of the state files.
* *
* @param string $pattern state pattern for glob()
*
* @access public * @access public
* @return array * @return array
*/ */
protected function getStateFiles() { protected function getStateFiles($pattern = STATE_DIR.'*/*/*') {
if (empty($this->statefiles)) { if (empty($this->statefiles) || $pattern != $this->pattern) {
$this->statefiles = glob(STATE_DIR. '*/*/*', GLOB_NOSORT); $this->statefiles = glob($pattern, GLOB_NOSORT);
$this->pattern = $pattern;
} }
return $this->statefiles; return $this->statefiles;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment