Fixed presentation slides upload issue

Change-Id: I554e103d574c3f79911dd30abc28330eacd82775
This commit is contained in:
smarcet 2019-09-10 18:41:50 -03:00
parent 8bd1d7e3e6
commit d65b404d60
3 changed files with 23 additions and 8 deletions

View File

@ -53,17 +53,28 @@ final class FileUploader implements IFileUploader
$attachment = new File(); $attachment = new File();
try { try {
$local_path = Storage::putFileAs(sprintf('/public/%s', $folder_name), $file, $file->getClientOriginalName()); $client_original_name = $file->getClientOriginalName();
Log::debug(sprintf("FileUploader::build: folder_name %s client original name %s", $folder_name, $client_original_name));
$local_path = Storage::putFileAs(sprintf('/public/%s', $folder_name), $file, $client_original_name);
Log::debug(sprintf("FileUploader::build: saved to local path %s", $local_path));
Log::debug(sprintf("FileUploader::build: invoking folder service findOrMake folder_name %s", $folder_name));
$folder = $this->folder_service->findOrMake($folder_name); $folder = $this->folder_service->findOrMake($folder_name);
$local_path = Storage::disk()->path($local_path); $local_path = Storage::disk()->path($local_path);
$attachment->setParent($folder); $attachment->setParent($folder);
$attachment->setName($file->getClientOriginalName()); $attachment->setName($client_original_name);
$attachment->setFilename(sprintf("assets/%s/%s", $folder_name, $file->getClientOriginalName())); $file_name = sprintf("assets/%s/%s", $folder_name, $client_original_name);
$attachment->setTitle(str_replace(array('-', '_'), ' ', preg_replace('/\.[^.]+$/', '', $file->getClientOriginalName()))); Log::debug(sprintf("FileUploader::build file_name %s", $file_name));
$title = str_replace(array('-', '_'), ' ', preg_replace('/\.[^.]+$/', '', $file->getClientOriginalName()));
$attachment->setFilename($file_name);
Log::debug(sprintf("FileUploader::build title %s", $title));
$attachment->setTitle($title);
$attachment->setShowInSearch(true); $attachment->setShowInSearch(true);
if ($is_image) // set className if ($is_image) // set className
$attachment->setImage(); $attachment->setImage();
Log::debug(sprintf("FileUploader::build uploading to bucket %s", $local_path));
$this->bucket->put($attachment, $local_path); $this->bucket->put($attachment, $local_path);
$attachment->setCloudMeta('LastPut', time()); $attachment->setCloudMeta('LastPut', time());
$attachment->setCloudStatus('Live'); $attachment->setCloudStatus('Live');

View File

@ -11,6 +11,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use Illuminate\Support\Facades\Log;
use libs\utils\ITransactionService; use libs\utils\ITransactionService;
use models\main\File; use models\main\File;
use models\main\IFolderRepository; use models\main\IFolderRepository;
@ -46,7 +48,7 @@ final class FolderService
public function findOrMake($folder_name) public function findOrMake($folder_name)
{ {
return $this->tx_service->transaction(function() use($folder_name){ return $this->tx_service->transaction(function() use($folder_name){
Log::debug(sprintf("FolderService::findOrMake folder_name %s", $folder_name));
$folder = $this->folder_repository->getFolderByFileName($folder_name); $folder = $this->folder_repository->getFolderByFileName($folder_name);
if(!is_null($folder)) return $folder; if(!is_null($folder)) return $folder;
@ -57,10 +59,12 @@ final class FolderService
$item = null; $item = null;
$file_name = null; $file_name = null;
foreach($parts as $part) { foreach($parts as $part) {
Log::debug(sprintf("FolderService::findOrMake part %s", $part));
if(!$part) continue; // happens for paths with a trailing slash if(!$part) continue; // happens for paths with a trailing slash
if(!empty($file_name)) if(!empty($file_name))
$file_name .= '/'; $file_name .= '/';
$file_name .= $part; $file_name .= $part;
Log::debug(sprintf("FolderService::findOrMake file_name %s", $file_name));
$item = is_null($parent) ? $item = is_null($parent) ?
$this->folder_repository->getFolderByName($part) : $this->folder_repository->getFolderByName($part) :
$this->folder_repository->getFolderByNameAndParent($part, $parent); $this->folder_repository->getFolderByNameAndParent($part, $parent);

View File

@ -714,7 +714,7 @@ final class PresentationService
$slideFile = $this->file_uploader->build( $slideFile = $this->file_uploader->build(
$file, $file,
sprintf('summits/%s/presentations/%s/slides/', $presentation->getSummitId(), $presentation_id), sprintf('summits/%s/presentations/%s/slides', $presentation->getSummitId(), $presentation_id),
false); false);
$slide->setSlide($slideFile); $slide->setSlide($slideFile);
} }
@ -806,7 +806,7 @@ final class PresentationService
throw new ValidationException(sprintf("file exceeds max_file_size (%s MB).", ($max_file_size / 1024) / 1024)); throw new ValidationException(sprintf("file exceeds max_file_size (%s MB).", ($max_file_size / 1024) / 1024));
} }
$slideFile = $this->file_uploader->build($file, sprintf('summits/%s/presentations/%s/slides/', $presentation->getSummitId(), $presentation_id), false); $slideFile = $this->file_uploader->build($file, sprintf('summits/%s/presentations/%s/slides', $presentation->getSummitId(), $presentation_id), false);
$slide->setSlide($slideFile); $slide->setSlide($slideFile);
$slide->clearLink(); $slide->clearLink();
} }