Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Update tags by directly setting them inside the shareData if possible…
Browse files Browse the repository at this point in the history
…, in the metadata otherwise.
  • Loading branch information
cdujeu committed May 9, 2014
1 parent e2e75f4 commit 3b2e53c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 78 deletions.
99 changes: 31 additions & 68 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -425,27 +425,36 @@ public function switchAction($action, $httpVars, $fileVars)

case "update_shared_element_data":

if(!in_array($httpVars["p_name"], array("counter", "tags"))){
return;
}
$hash = AJXP_Utils::decodeSecureMagic($httpVars["element_id"]);
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
if(!in_array($httpVars["p_name"], array("counter", "tags")));
$ajxpNode = new AJXP_Node($this->urlBase.$file);
$metadata = $ajxpNode->retrieveMetadata(
"ajxp_shared",
true,
AJXP_METADATA_SCOPE_REPOSITORY
);
if (isSet($metadata["element"][$httpVars["element_id"]])) {
if (!is_array($metadata["element"][$httpVars["element_id"]])) {
$metadata["element"][$httpVars["element_id"]] = array();
}
$metadata["element"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
$ajxpNode->setMetadata(
if($this->getShareStore()->shareIsLegacy($hash)){
// Store in metadata
$ajxpNode = new AJXP_Node($this->urlBase.$file);
$metadata = $ajxpNode->retrieveMetadata(
"ajxp_shared",
$metadata,
true,
AJXP_METADATA_SCOPE_REPOSITORY);
AJXP_METADATA_SCOPE_REPOSITORY
);
if (isSet($metadata["shares"][$httpVars["element_id"]])) {
if (!is_array($metadata["shares"][$httpVars["element_id"]])) {
$metadata["shares"][$httpVars["element_id"]] = array();
}
$metadata["shares"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
$ajxpNode->setMetadata(
"ajxp_shared",
$metadata,
true,
AJXP_METADATA_SCOPE_REPOSITORY);
}
}else{
$this->getShareStore()->updateShareProperty($hash, $httpVars["p_name"], $httpVars["p_value"]);
}

break;

break;

default:
break;
Expand Down Expand Up @@ -639,58 +648,6 @@ public function forwardEventToSharesAction($actionName, $httpVars, $fileVars){
}
}

/**
* @var AJXP_Node
*/
private static $updateNodeMeta;

/**
*
* Hooked to node.change, this will update the index
* if $oldNode = null => create node $newNode
* if $newNode = null => delete node $oldNode
* Else copy or move oldNode to newNode.
*
* @param AJXP_Node $oldNode
*/
public function updateNodeSharedData11($oldNode)
{
return;

if(empty($this->accessDriver) || $this->accessDriver->getId() == "access.imap") return;
if($oldNode == null || !$oldNode->hasMetaStore()) return;
$metadata = $oldNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
if (count($metadata) && !empty($metadata["element"])) {
$oldNode->loadNodeInfo();
try {
$type = $oldNode->isLeaf() ? "file":"repository";
$elementIds = array();
if(!$oldNode->isLeaf() || $metadata["minisite"]){
self::$updateNodeMeta = $oldNode;
return;
}else{
self::$updateNodeMeta = null;
}
if ($type == "file") {
if(!is_array($metadata["element"])) $elementIds[] = $metadata["element"];
else $elementIds = array_keys($metadata["element"]);
} else {
$elementIds[]= $metadata["element"];
}
foreach ($elementIds as $elementId) {
$this->getShareStore()->deleteShare(
$type,
$elementId,
AuthService::getLoggedUser()->getId()
);
}
$oldNode->removeMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
} catch (Exception $e) {
$this->logError("Exception", $e->getMessage(), $e->getTrace() );
}
}
}

/**
* @param AJXP_Node $oldNode
* @param AJXP_Node $newNode
Expand Down Expand Up @@ -1989,6 +1946,9 @@ public function shareToJson($shareId, $shareData, $node = null){
if (!count($pData)) {
return false;
}
foreach($this->getShareStore()->modifiableShareKeys as $key){
if(isSet($pData[$key])) $shareData[$key] = $pData[$key];
}
if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId() && !AuthService::getLoggedUser()->isAdmin()) {
throw new Exception($messages["share_center.48"]);
}
Expand Down Expand Up @@ -2090,6 +2050,9 @@ public function shareToJson($shareId, $shareData, $node = null){
"public_link" => $minisiteLink,
"disable_download" => $dlDisabled
);
foreach($this->getShareStore()->modifiableShareKeys as $key){
if(isSet($minisiteData[$key])) $jsonData[$key] = $minisiteData[$key];
}

}

Expand Down
17 changes: 17 additions & 0 deletions core/src/plugins/action.share/class.ShareStore.php
Expand Up @@ -28,6 +28,7 @@ class ShareStore {
var $sqlSupported = false;
var $downloadFolder;
var $hashMinLength;
public $modifiableShareKeys = array("counter", "tags", "short_form_url");
/**
* @var sqlConfDriver
*/
Expand Down Expand Up @@ -146,6 +147,22 @@ public function loadShare($hash){

}

public function shareIsLegacy($hash){
$dlFolder = $this->downloadFolder;
$file = $dlFolder."/".$hash.".php";
return is_file($file);
}

public function updateShareProperty($hash, $pName, $pValue){
$relatedObjectId = $this->confStorage->simpleStoreGet("share", $hash, "serial", $data);
if(is_array($data)){
$data[$pName] = $pValue;
$this->confStorage->simpleStoreSet("share", $hash, $data, "serial", $relatedObjectId);
return true;
}
return false;
}

public function findSharesForRepo($repositoryId){
return $this->confStorage->simpleStoreList("share", null, "", "serial", '%"REPOSITORY";s:32:"'.$repositoryId.'"%');
}
Expand Down
20 changes: 10 additions & 10 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -410,28 +410,28 @@
<serverCallback methodName="forwardEventToSharesAction"/>
</processing>
</action>
<action name="sharelist-refresh">
<gui src="share.png" iconClass="icon-refresh" text="149" title="149">
<context dir="true" recycle="false" selection="false" actionBar="true" actionBarGroup="repo_editor_shares" behaviour="hidden"/>
<action name="sharelist-edit">
<gui src="share.png" iconClass="icon-share" text="share_center.125" title="share_center.126">
<context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="repo_editor_shares" behaviour="hidden"/>
<selectionContext dir="true" file="true" evalMetadata="metadata.get('ajxp_shared')" recycle="false" unique="true" behaviour="hidden"/>
</gui>
<processing>
<clientCallback prepareModal="true"><![CDATA[
if(!ajaxplorer.actionBar.shareCenter) ajaxplorer.actionBar.shareCenter = new ShareCenter();
if(window.actionManager){
window.actionManager.getDataModel().requireContextChange(window.actionManager.getDataModel().getRootNode(), true);
ajaxplorer.actionBar.shareCenter.performShareAction(window.actionManager.getDataModel());
}
]]></clientCallback>
</processing>
</action>
<action name="sharelist-edit">
<gui src="share.png" iconClass="icon-share" text="share_center.125" title="share_center.126">
<context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="repo_editor_shares" behaviour="hidden"/>
<selectionContext dir="true" file="true" evalMetadata="metadata.get('ajxp_shared')" recycle="false" unique="true" behaviour="hidden"/>
<action name="sharelist-refresh">
<gui src="share.png" iconClass="icon-refresh" text="149" title="149">
<context dir="true" recycle="false" selection="false" actionBar="true" actionBarGroup="repo_editor_shares" behaviour="hidden"/>
</gui>
<processing>
<clientCallback prepareModal="true"><![CDATA[
if(!ajaxplorer.actionBar.shareCenter) ajaxplorer.actionBar.shareCenter = new ShareCenter();
if(window.actionManager){
ajaxplorer.actionBar.shareCenter.performShareAction(window.actionManager.getDataModel());
window.actionManager.getDataModel().requireContextChange(window.actionManager.getDataModel().getRootNode(), true);
}
]]></clientCallback>
</processing>
Expand Down

0 comments on commit 3b2e53c

Please sign in to comment.