Permalink
Browse files

Fix various condition issues

  • Loading branch information...
1 parent 1e28a12 commit 4b3658b46f933bb3e8eae8f37f9da942423febae @cdujeu cdujeu committed May 27, 2016
@@ -366,6 +366,10 @@ public static function migrateLegacyMeta($shareCenter, $shareStore, $shareRightM
if(file_exists($legacyLinkFile)){
// Load file, move it to DB and move the meta
$publiclet = $shareStore->loadShare($element);
+ if($publiclet === false){
+ print("\n--Could not load publiclet $element, skipping");
+ continue;
+ }
rename($legacyLinkFile, $legacyLinkFile.".migrated");
if(isSet($share["minisite"])){
print("\n--Migrate legacy minisite to new minisite?");
@@ -186,9 +186,9 @@ public function parseHttpVars($httpVars){
// Existing already
$value = Utils::sanitize($httpVars["custom_handle"], AJXP_SANITIZE_ALPHANUM);
$value = strtolower($value);
- if(strlen($value) < $this->store->hashMinLength){
+ if(strlen($value) < $this->store->getHashMinLength()){
$mess = ConfService::getMessages();
- throw new \Exception(str_replace("%s", $this->store->hashMinLength, $mess["share_center.223"]));
+ throw new \Exception(str_replace("%s", $this->store->getHashMinLength(), $mess["share_center.223"]));
}
$test = $this->store->loadShare($value);
$mess = ConfService::getMessages();
@@ -379,7 +379,7 @@ public function getDownloadLimit(){
}
public static function isShareExpired($data){
- return ($data["EXPIRE_TIME"] && time() > $data["EXPIRE_TIME"]) ||
+ return (isSet($data["EXPIRE_TIME"]) && time() > $data["EXPIRE_TIME"]) ||
($data["DOWNLOAD_LIMIT"] && $data["DOWNLOAD_LIMIT"]> 0 && isSet($data["DOWNLOAD_COUNT"]) && $data["DOWNLOAD_LIMIT"] <= $data["DOWNLOAD_COUNT"]);
}
@@ -1226,6 +1226,11 @@ public static function loadShareByHash($hash){
$shareCenter = self::getShareCenter();
$data = $shareCenter->getShareStore()->loadShare($hash);
$mess = ConfService::getMessages();
+ if($data === false){
+ AuthService::disconnect();
+ self::loadMinisite([], $hash, $mess["share_center.166"]);
+ return;
+ }
if(ShareLink::isShareExpired($data)){
AuthService::disconnect();
self::loadMinisite($data, $hash, $mess["share_center.165"]);
@@ -40,7 +40,11 @@ class ShareStore {
var $sqlSupported = false;
var $downloadFolder;
- var $hashMinLength;
+ /**
+ * @var int
+ */
+ private $hashMinLength;
+
public $modifiableShareKeys = array("counter", "tags", "short_form_url");
/**
* @var sqlConfDriver
@@ -59,6 +63,10 @@ public function __construct($downloadFolder, $hashMinLength = 32){
}
}
+ public function getHashMinLength(){
+ return $this->hashMinLength;
+ }
+
/**
* @return ShareMetaManager
*/
@@ -442,7 +450,7 @@ public function deleteShare($type, $element, $keepRepository = false, $ignoreRep
AuthService::deleteUser($element);
} else if ($type == "file") {
$publicletData = $this->loadShare($element);
- if (isSet($publicletData["OWNER_ID"]) && $this->testUserCanEditShare($publicletData["OWNER_ID"], $publicletData)) {
+ if ($publicletData!== false && isSet($publicletData["OWNER_ID"]) && $this->testUserCanEditShare($publicletData["OWNER_ID"], $publicletData)) {
if(isSet($publicletData["PUBLICLET_PATH"]) && is_file($publicletData["PUBLICLET_PATH"])){
unlink($publicletData["PUBLICLET_PATH"]);
}else if($this->sqlSupported){
@@ -656,18 +664,7 @@ public function resetDownloadCounter($hash, $userId){
$share->resetDownloadCount();
$share->save();
}
-
- /**
- * Check if share is expired
- * @param string $hash
- * @param array $data
- * @return bool
- */
- public function isShareExpired($hash, $data){
- return ($data["EXPIRE_TIME"] && time() > $data["EXPIRE_TIME"]) ||
- ($data["DOWNLOAD_LIMIT"] && $data["DOWNLOAD_LIMIT"]> 0 && isSet($data["DOWNLOAD_COUNT"]) && $data["DOWNLOAD_LIMIT"] <= $data["DOWNLOAD_COUNT"]);
- }
-
+
/**
* Find all expired shares and remove them.
* @param bool|true $currentUser
@@ -692,8 +689,7 @@ public function clearExpiredFiles($currentUser = true)
if ($currentUser && ( !isSet($publicletData["OWNER_ID"]) || $publicletData["OWNER_ID"] != $userId )) {
continue;
}
- if( (isSet($publicletData["EXPIRE_TIME"]) && is_numeric($publicletData["EXPIRE_TIME"]) && $publicletData["EXPIRE_TIME"] > 0 && $publicletData["EXPIRE_TIME"] < time()) ||
- (isSet($publicletData["DOWNLOAD_LIMIT"]) && $publicletData["DOWNLOAD_LIMIT"] > 0 && isSet($publicletData["DOWNLOAD_COUNT"]) && $publicletData["DOWNLOAD_LIMIT"] <= $publicletData["DOWNLOAD_COUNT"]) ) {
+ if (ShareLink::isShareExpired($publicletData)){
if(!$currentUser) $switchBackToOriginal = true;
$this->deleteExpiredPubliclet($hash, $publicletData);
$deleted[] = $publicletData["FILE_PATH"];

0 comments on commit 4b3658b

Please sign in to comment.