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

Commit

Permalink
Fix #1108: Caching issues for unoconv-generated previews of office fi…
Browse files Browse the repository at this point in the history
…les.
  • Loading branch information
cdujeu committed Jul 4, 2016
1 parent 94a5e24 commit 4877ba3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
25 changes: 13 additions & 12 deletions core/src/plugins/editor.diaporama/class.Diaporama.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,7 @@ Class.create("Diaporama", AbstractEditor, {
updateImage : function(){

var node = this.nodes.get(this.currentFile);
var mstring = '';
if(node && node.getMetadata().get('ajxp_modiftime')){
mstring = '&time_seed=' + node.getMetadata().get('ajxp_modiftime');
}
var mstring = this.buildRandomSeed(node);

if(node && node.getMetadata().get("image_dimensions_thumb")){
var sizeLoader = new Image();
Expand Down Expand Up @@ -817,18 +814,22 @@ Class.create("Diaporama", AbstractEditor, {

getThumbnailSource : function(ajxpNode){
var repoString = "";
if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
}
var mtimeString = this.buildRandomSeed(ajxpNode);
return pydioBootstrap.parameters.get('ajxpServerAccess') + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
},

buildRandomSeed : function(ajxpNode){
var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
var source = ajxpServerAccessPath + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
if(ajxpNode.getParent()){
if(ajxpNode.getParent()){
var preview_seed = ajxpNode.getParent().getMetadata().get('preview_seed');
if(preview_seed){
source += "&rand="+preview_seed;
}
if(preview_seed){
mtimeString += "&rand="+preview_seed;
}
}
return source;
}
return mtimeString;
}

});
12 changes: 7 additions & 5 deletions core/src/plugins/editor.imagick/class.IMagickPreviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Class.create("IMagickPreviewer", Diaporama, {
actions : {}
}, editorOptions);
$super(oFormObject, options);
this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page&file=";
this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page";
// Override onload for the text
this.jsImage.onload = function(){
this.jsImageLoading = false;
Expand All @@ -53,6 +53,7 @@ Class.create("IMagickPreviewer", Diaporama, {

open : function($super, node)
{
this.inputNode = node;
this.src_file = node.getPath();
this.currentIM = getBaseName(this.src_file);
// Extract the pages and load result!
Expand Down Expand Up @@ -170,11 +171,11 @@ Class.create("IMagickPreviewer", Diaporama, {

getThumbnailSource : function(ajxpNode){
var repoString = "";
if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
}
var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
return ajxpServerAccessPath+"&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
var mtimeString = this.buildRandomSeed(ajxpNode);
return pydioBootstrap.parameters.get('ajxpServerAccess') + "&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
},

setOnLoad: function() {
Expand All @@ -198,9 +199,10 @@ Class.create("IMagickPreviewer", Diaporama, {
if(this.crtWidth){
this.crtRatio = this.crtHeight / this.crtWidth;
}
var mstring = this.buildRandomSeed(this.inputNode);
new Effect.Opacity(this.imgTag, {afterFinish : function(){
this.jsImageLoading = true;
this.jsImage.src = this.baseUrl + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
this.jsImage.src = this.baseUrl + mstring + "&file=" + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
if(!this.crtWidth && !this.crtHeight){
this.crtWidth = this.imgTag.getWidth();
this.crtHeight = this.imgTag.getHeight();
Expand Down
23 changes: 22 additions & 1 deletion core/src/plugins/editor.imagick/class.IMagickPreviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,34 @@ public function deleteImagickCache($oldNode, $newNode = null, $copy = false)
// Should remove imagick cache file
if(!$this->handleMime($oldFile)) return;
if ($newNode == null || $copy == false) {

// Main Thumb
AJXP_Cache::clearItem("imagick_thumb", $oldFile);

// Unoconv small PDF
$thumbCache = AJXP_Cache::getItem("imagick_thumb", $oldFile, false);
$unoFile = pathinfo($thumbCache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($thumbCache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
if(file_exists($unoFile)){
unlink($unoFile);
}

$cache = AJXP_Cache::getItem("imagick_full", $oldFile, false);
// Unoconv full pdf
$unoFile = pathinfo($cache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($cache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
if(file_exists($unoFile)){
unlink($unoFile);
}
$prefix = str_replace(".".pathinfo($cache->getId(), PATHINFO_EXTENSION), "", $cache->getId());
// Additional Extracted pages
$files = $this->listExtractedJpg($oldFile, $prefix);
$cacheDir = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/imagick_full";
foreach ($files as $file) {
if(is_file((defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/".$file["file"])) unlink(AJXP_CACHE_DIR."/".$file["file"]);
if(is_file($cacheDir."/".$file["file"])) {
unlink($cacheDir."/".$file["file"]);
}
}


}
}

Expand Down

0 comments on commit 4877ba3

Please sign in to comment.