diff --git a/composer.json b/composer.json index 060725e..2d6c4a3 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "authors":[{"name":"Carsten Wallenhauer","email":"admin@datapool.info"}], "require":{ "php":">=8.0", - "phpoffice/phpspreadsheet":"^1.28", + "phpoffice/phpspreadsheet":">=2.2.1", "michelf/php-markdown":"^2.0.0", "monolog/monolog":"^3.5.0", "psr/log":"^3", diff --git a/src/php/Components/Login.php b/src/php/Components/Login.php index 31d3530..3f6729d 100644 --- a/src/php/Components/Login.php +++ b/src/php/Components/Login.php @@ -72,7 +72,7 @@ private function loginRequest(array $arr) $this->loginFailed($user,$arr['Email']); } else if (strcmp($loginEntry['Name'],$arr['Passphrase'])===0){ $this->oc['SourcePot\Datapool\Foundation\Database']->deleteEntries($loginEntry,TRUE); - $this->oc['logger']->log('info','One-time login for {email} at {timestamp} successful.',array('email'=>$arr['Email'],'timestamp'=>time())); + $this->oc['logger']->log('info','One-time login for {email} at {dateTime} was successful.',array('email'=>$arr['Email'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); $this->loginSuccess($user,$arr['Email']); } else { $this->loginFailed($user,$arr['Email']); @@ -96,13 +96,13 @@ private function resetSession(){ private function loginSuccess($user,$email){ $this->resetSession(); $this->oc['SourcePot\Datapool\Foundation\User']->loginUser($user); - $this->oc['logger']->log('info','Login for {email} at {timestamp} successful.',array('email'=>$email,'timestamp'=>time())); + $this->oc['logger']->log('info','Login for {email} at {dateTime} was successful.',array('email'=>$email,'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Home'))); } private function loginFailed($user,$email){ $_SESSION['currentUser']['Privileges']=1; - $this->oc['logger']->log('error','Login failed for {email} at {timestamp}.',array('email'=>$email,'timestamp'=>time())); + $this->oc['logger']->log('notice','Login failed for {email} at {dateTime}.',array('email'=>$email,'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); sleep(30); header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Login'))); } @@ -126,7 +126,7 @@ private function registerRequest($arr){ } } if (empty($err)){ - $this->oc['logger']->log('info','You have been registered as new user ({email}).',array('email'=>$arr['Email'])); + $this->oc['logger']->log('info','You have been registered as new user ({email}) at {dateTime}.',array('email'=>$arr['Email'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Admin'))); exit; } else { diff --git a/src/php/Components/Logout.php b/src/php/Components/Logout.php index 26237c9..34ccc5e 100644 --- a/src/php/Components/Logout.php +++ b/src/php/Components/Logout.php @@ -27,7 +27,7 @@ public function run(array|bool $arr=TRUE):array{ if ($arr===TRUE){ return array('Category'=>'Logout','Emoji'=>'✖','Label'=>'Logout','Read'=>'ALL_REGISTERED_R','Class'=>__CLASS__); } else { - $this->oc['logger']->log('info','User logout {user}',array('user'=>$_SESSION['currentUser']['Name'])); + $this->oc['logger']->log('info','User logout {user} at {dateTime}',array('user'=>$_SESSION['currentUser']['Name'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); // reset session | keep page state $_SESSION=array('page state'=>$_SESSION['page state']); session_regenerate_id(TRUE); diff --git a/src/php/Foundation/Database.php b/src/php/Foundation/Database.php index 0f6ee4d..aa63cdd 100644 --- a/src/php/Foundation/Database.php +++ b/src/php/Foundation/Database.php @@ -227,7 +227,7 @@ public function setTableIndices(string $table) * This function selects the entry-specific unifyEntry() function based on $entry['Source'] * If the $entry-specific unifyEntry() function is found it will be used to unify the entry. */ - public function unifyEntry(array $entry):array + public function unifyEntry(array $entry,bool $addDefaults):array { if (empty($entry['Source'])){ throw new \ErrorException('Method '.__FUNCTION__.' called with empty entry Source.',0,E_ERROR,__FILE__,__LINE__); @@ -236,10 +236,10 @@ public function unifyEntry(array $entry):array $classWithNamespace=$this->oc['SourcePot\Datapool\Root']->source2class($entry['Source']); if (isset($this->oc[$classWithNamespace])){ if (method_exists($this->oc[$classWithNamespace],'unifyEntry')){ - $entry=$this->oc[$classWithNamespace]->unifyEntry($entry); + $entry=$this->oc[$classWithNamespace]->unifyEntry($entry,$addDefaults); } } - $entry=$this->addEntryDefaults($entry); + if ($addDefaults){$entry=$this->addEntryDefaults($entry);} $entry=$this->oc['SourcePot\Datapool\Root']->substituteWithPlaceholder($entry); return $entry; } @@ -849,7 +849,7 @@ public function updateEntry(array $entry,bool $isSystemCall=FALSE,bool $noUpdate $entry=$this->addLog2entry($entry,'Processing log',array('msg'=>'Entry updated','Expires'=>date('Y-m-d H:i:s',time()+604800)),FALSE); } // update entry - $entry=$this->unifyEntry($entry); + $entry=$this->unifyEntry($entry,FALSE); $this->updateEntries($selector,$entry,$isSystemCall,'Write',FALSE,FALSE,FALSE,FALSE,array(),FALSE,$isDebugging=FALSE); $entry=$this->entryById($selector,$isSystemCall,'Read'); } else { @@ -908,9 +908,11 @@ public function hasEntry(array $selector,bool $isSystemCall=TRUE,string $rightTy */ public function moveEntryOverwriteTarget($sourceEntry,$targetSelector,$isSystemCall=TRUE,$isTestRun=FALSE,$keepSource=FALSE,$updateSourceFirst=FALSE):array { + $context=array('class'=>__CLASS__,'function'=>__FUNCTION__); // test for required keys and set selector - if (empty($sourceEntry['Source']) || empty($sourceEntry['EntryId'])){ - throw new \ErrorException('Function '.__FUNCTION__.': Mandatory sourceEntry-key(s) missing, either Source or EntryId',0,E_ERROR,__FILE__,__LINE__); + if (empty($sourceEntry['Source']) || empty($sourceEntry['EntryId']) || empty($targetSelector)){ + $this->oc['logger']->log('error','{class} → {function} called with empty sourceEntry[Source], sourceEntry[EntryId] or targetEntry. Source entry was not moved.',$context); + return array(); } if ($this->oc['SourcePot\Datapool\Foundation\Access']->access($sourceEntry,'Write',FALSE,$isSystemCall)){ // write access diff --git a/src/php/Foundation/Definitions.php b/src/php/Foundation/Definitions.php index d30a7cd..a15c115 100644 --- a/src/php/Foundation/Definitions.php +++ b/src/php/Foundation/Definitions.php @@ -330,8 +330,7 @@ public function entry2form(array $entry=array(),bool $isDebugging=FALSE):string $debugArr['entry_updated']=$this->oc['SourcePot\Datapool\Foundation\Filespace']->fileUpload2entry($fileArr,$entry); } } else { - $entry['skipUpdateCalendarEventEntry']=FALSE; - $debugArr['entry_updated']=$this->oc[$dataStorageClass]->updateEntry($entry); + $debugArr['entry_updated']=$this->oc[$dataStorageClass]->updateEntry($entry,FALSE,FALSE,$addLog=FALSE); } $statistics=$this->oc[$dataStorageClass]->getStatistic(); $entryType=(isset($entry['Source']))?strval($entry['Source']):strval($entry['Class']); diff --git a/src/php/Foundation/User.php b/src/php/Foundation/User.php index 4808820..eda46b8 100644 --- a/src/php/Foundation/User.php +++ b/src/php/Foundation/User.php @@ -154,7 +154,7 @@ public function getCurrentUser():array return $_SESSION['currentUser']; } - public function unifyEntry(array $entry):array + public function unifyEntry(array $entry,bool $addDefaults=FALSE):array { $entry['Source']=$this->entryTable; if (!isset($entry['Content']['Address'])){$entry['Content']['Address']=array();} @@ -164,11 +164,13 @@ public function unifyEntry(array $entry):array if (empty($entry['Params']['User registration']['Email']) && !empty($entry['Content']['Contact details']['Email'])){ $entry['Params']['User registration']['Email']=$entry['Content']['Contact details']['Email']; } - $entry=$this->oc['SourcePot\Datapool\Foundation\Access']->addRights($entry,'ADMIN_R','ADMIN_R'); $entry['Group']=$this->oc['SourcePot\Datapool\Foundation\Backbone']->getSettings('pageTitle'); $entry['Folder']=$this->getUserRolsString($entry); + if ($addDefaults){ + $entry=$this->oc['SourcePot\Datapool\Foundation\Access']->addRights($entry,'ADMIN_R','ADMIN_R'); + $entry=$this->oc['SourcePot\Datapool\Foundation\Definitions']->definition2entry($this->definition,$entry,FALSE); + } $entry=$this->oc['SourcePot\Datapool\Tools\GeoTools']->address2location($entry); - $entry=$this->oc['SourcePot\Datapool\Foundation\Definitions']->definition2entry($this->definition,$entry,FALSE); $entry['Name']=$this->userAbstract(array('selector'=>$entry),3); return $entry; } @@ -311,7 +313,7 @@ public function loginUser(array $user) { $_SESSION['currentUser']=$user; if (strcmp($user['Owner'],'ANONYM')!==0){ - $this->oc['logger']->log('info','User login {user}',array('user'=>$_SESSION['currentUser']['Name'])); + $this->oc['logger']->log('info','User login {user} at {dateTime}',array('user'=>$_SESSION['currentUser']['Name'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)'))); } } diff --git a/src/php/Tools/MiscTools.php b/src/php/Tools/MiscTools.php index 5f39137..6acdb25 100644 --- a/src/php/Tools/MiscTools.php +++ b/src/php/Tools/MiscTools.php @@ -300,7 +300,7 @@ public function addEntryId(array $entry,array $relevantKeys=array('Source','Grou return $entry; } - public function getDateTime(string $datetime='now',string $addDateInterval='',string $timezone=''):string + public function getDateTime(string $datetime='now',string $addDateInterval='',string $timezone='',string $format='Y-m-d H:i:s'):string { if ($datetime[0]==='@'){ $timestamp=intval(trim($datetime,'@')); @@ -319,7 +319,7 @@ public function getDateTime(string $datetime='now',string $addDateInterval='',st } } $dateTime->setTimeZone(new \DateTimeZone(\SourcePot\Datapool\Root::DB_TIMEZONE)); - return $dateTime->format('Y-m-d H:i:s'); + return $dateTime->format($format); } public function code2utf(int $code):string