Server sync

This commit is contained in:
2019-10-05 00:34:18 +02:00
parent 4cc305e8b5
commit d72c6c0dde
11 changed files with 163 additions and 16 deletions

View File

@@ -52,7 +52,7 @@ class Doc extends PhpObject {
}
}
$asData = array_merge($this->getDocKeys(), array('filename'=>$sFileName, 'type'=>$sType));
$asData = array_merge($this->getDocKeys(), array('type'=>$sType, 'filename'=>$sFileName, 'filehash'=>self::getChecksum($sFileName)));
$bResult = $this->oDb->insertRow(self::DOC_TABLE, $asData);
return $bResult?'':'error_db';
@@ -73,18 +73,54 @@ class Doc extends PhpObject {
return array_shift($asDocList);
}
public function getList($asConstraint=array()) {
$asKeys = empty($asConstraint)?$this->getDocKeys():$asConstraint;
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$asKeys));
foreach($asDocs as &$asDoc) $asDoc['filepath'] = self::getFilePath($asDoc['filename']);
public function getList($oOption='self') {
if($oOption=='self') $asKeys = $this->getDocKeys();
elseif($oOption=='full') $asKeys = array();
elseif(is_array($oOption)) $asKeys = $oOption;
else return array();
$asDocs = $this->oDb->selectRows(array(
'select' => array(Db::getId(self::DOC_TABLE), 'type', 'filename', 'filehash'),
'from' => self::DOC_TABLE,
'constraint'=> $asKeys
));
foreach($asDocs as &$asDoc) {
$asDoc['filepath'] = self::getFilePath($asDoc['filename']);
//TODO remove. For upgrade purposes only
if($asDoc['filehash']=='') {
$asDoc['filehash'] = self::getChecksum($asDoc['filename']);
$this->oDb->updateRow(self::DOC_TABLE, $asDoc[Db::getId(self::DOC_TABLE)], array('filehash'=>$asDoc['filehash']), false);
}
}
return $asDocs;
}
public function getMissingFiles() {
$asDocs = $this->getList('full');
$asMissingFiles = array();
foreach($asDocs as $asDoc) {
$sHash = self::getChecksum($asDoc['filename']);
if(!file_exists($asDoc['filepath']) || $sHash!=$asDoc['filehash']) {
$asDoc['actual_hash'] = $sHash;
$asMissingFiles[] = $asDoc;
}
}
return $asMissingFiles;
}
private function getDocKeys() {
return array(Db::getId(Auth::USER_TABLE) => $this->iUserId, Db::getId(Course::WS_TABLE) => $this->iWorkshopId);
}
private static function getChecksum($sFileName) {
$sFilePath = self::getFilePath($sFileName);
return file_exists($sFilePath)?sha1_file($sFilePath):'';
}
private static function getFilePath($sFileName) {
return self::DOC_FOLDER.$sFileName;
}