class Farm
{
-
protected static $_outPDF = [];
protected static $_forceServer = false;
+
//protected static $_forceServer = 'alphaville';
+
+ protected static $_region = 'UE';
+
protected static $_farmServers = [
['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 12, 'region' => 'UE'],
- ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6, 'region' => 'US'],
+ ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6, 'region' => 'UE'],
['name' => 'clockwork', 'host' => 'clockwork.cubedesigners.com', 'weight' => 2, 'region' => 'UE'],
['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 6, 'region' => 'UE'],
['name' => 'dobermann', 'host' => 'dobermann.cubedesigners.com', 'weight' => 6, 'region' => 'UE'],
//['name' => 'nakedgun', 'host' => 'nakedgun.cubedesigners.com', 'weight' => 4, 'region' => 'UE'],
];
+ /**
+ * @param string $region
+ */
+ public static function setRegion(string $region): void
+ {
+ self::$_region = $region;
+ }
+
+ /**
+ * @return string
+ */
+ public static function getRegion(): string
+ {
+ return self::$_region;
+ }
+
public static function forceServer($server)
{
self::$_forceServer = $server;
return $farmServer;
}
for ($i = 0; $i < $farmServer['weight']; $i++) {
- $hat[] = $k;
+ if ($farmServer['region'] === self::getRegion()) {
+ $hat[] = $k;
+ }
}
}
shuffle($hat);
$fb = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id);
if ($type === 'originalpdf') {
$doc = $fb->getDocument($page);
- return XSendFileController::sendfile(protected_path('fluidbookpublication/docs/' . $doc->id . '/original.pdf'), 86400, ['Content-Disposition', 'attachment; filename="' . $doc->id . '.pdf"']);
+ return XSendFileController::sendfile($fb->protected_path('fluidbookpublication/docs/' . $doc->id . '/original.pdf'), 86400, ['Content-Disposition', 'attachment; filename="' . $doc->id . '.pdf"']);
}
$types = ['texts' => FluidbookDocument::TEXT_PLAIN, 'index' => FluidbookDocument::TEXT_INDEX, 'layout' => FluidbookDocument::TEXT_LAYOUT];
if (!isset($types[$type])) {
if (null === $file) {
abort(500);
}
+
+ $fluidbook_id = request('fluidbook_id');
+ $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id);
+
$document = new FluidbookDocument();
+ $document->region = $fluidbook->region;
$document->file = $file->getClientOriginalName();
$document->file_data = ["fileName" => $file->getClientOriginalName(), "fileSize" => $file->getSize(), "modificationDate" => $file->getMTime(), "creationDate" => $file->getCTime()];
$document->owner = backpack_user()->id;
$document->save();
move_uploaded_file($file->getPathname(), Files::mkdir($document->path()) . 'original.pdf');
FluidbookDocumentUpload::updateProgression($uploadID, $document->id, __('Mise en file d\'attente du traitement du document'), 1.2);
- FluidbookDocumentUpload::dispatch($uploadID, $document, backpack_user(), request('fluidbook_id', null));
+ FluidbookDocumentUpload::dispatch($uploadID, $document, backpack_user(), $fluidbook->id);
return response()->json(['uploadID' => $uploadID, 'document' => $document->id]);
}
abort(404);
}
- $relayPath = Files::mkdir(protected_path('/fluidbookpublication/delivery/'));
+ $relayPath = Files::mkdir(FluidbookPublication::getProtectedPath($id, '/fluidbookpublication/delivery/'));
$relayPath .= $id;
$relayPath .= $type === "desktop" ? '' : '-mobile';
$relayPath .= '.jpg';
if ($fluidbook->getPagesNumber() === 0) {
abort(404, __('Cette publication ne comporte aucune page'));
}
- $path = protected_path('fluidbookpublication/packager/download/' . $file);
+ $path = $fluidbook->protected_path('fluidbookpublication/packager/download/' . $file);
if (!file_exists($path)) {
abort(404, __('Le fichier n\'existe pas'));
}
// Mark the fluidbook as downloaded when status is ready and user is not an admin
if ($fluidbook->status == 1 && !can('fluidbook-publication:admin')) {
- $fluidbook->setStatus( 2);
+ $fluidbook->setStatus(2);
$fluidbook->save();
}
// Paths init
$baseDocument = $this->getPDFComplexBaseDocument($book);
- $destDir = Files::mkdir(protected_path('fluidbookpublication/cache/exportpdf/' . $book->id));
+ $destDir = Files::mkdir($book->protected_path('fluidbookpublication/cache/exportpdf/' . $book->id));
$fname = md5($baseDocument) . '-' . md5(implode(',%ù', $range) . ($print ? '1' : '0')) . '.pdf';
$destFile = $destDir . '/' . $fname;
public function _getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = true)
{
+ Farm::setRegion($this->region);
if (!$this->hasFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $forceCheck)) {
return Farm::getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path());
}
if (file_exists($thumbpdf)) {
try {
+ Farm::setRegion($this->region);
return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, null, $force, 1);
} catch (\Exception $e) {
throw new \Exception('Unable to generate thumbnails file from custom PDF "' . $this->pdfThumbnails . '" (original message : ' . $e->getMessage() . ')');
var form = $('<form id="compositionUploadForm" action="{{backpack_url($entry->getOption('name').'/uploaddocument')}}" enctype="multipart/form-data" method="post">' +
'<input type="file" id="compositionUploadBrowse" name="file" value="" accept=".pdf" />' +
'<input type="hidden" name="_token" value="{{csrf_token()}}" />' +
+ '<input type="hidden" name="fluidbook_id" value="{{$entry->id}}" />' +
'</form>');
$('#composition_uploader').append(form);
$("#compositionUploadBrowse").click();
@include('crud::fields.inc.wrapper_start')
<div id="composition">
<input
- id="compositionField"
- type="hidden"
- name="{{ $field['name'] }}"
- value="{{ $v }}"
- data-doc-sizes="{{ json_encode($entry->getDocumentSizes()) }}"
- @include('crud::fields.inc.attributes')
+ id="compositionField"
+ type="hidden"
+ name="{{ $field['name'] }}"
+ value="{{ $v }}"
+ data-doc-sizes="{{ json_encode($entry->getDocumentSizes()) }}"
+ @include('crud::fields.inc.attributes')
>
<div id="composition_uploader">
<a class="btn btn-primary" href="#" data-toggle="tooltip" title="{{__('Charger un PDF')}}"
id="compositionAddPDF"><i
- class="la la-upload"></i> {{__('Charger un PDF')}}</a>
+ class="la la-upload"></i> {{__('Charger un PDF')}}</a>
</div>
<div id="composition_pages"></div>
<div id="composition_history">