Commit 9f7056dd authored by Ricardo Walter Hildebrand's avatar Ricardo Walter Hildebrand
Browse files

Merge remote-tracking branch 'remotes/origin/20211117-download' into homologacao

parents 4b13a4ca 4f60517c
Pipeline #4621 passed with stages
in 6 minutes and 28 seconds
......@@ -150,8 +150,10 @@ class MaterialController extends Controller
}
if ($request->hasFile('file')) {
$mediaCount = 1;
$material->content = handle_module_upload($request->file('file'), $mediaCount);
$downloadUrl = null;
$material->content = handle_module_upload($request->file('file'), $mediaCount, $downloadUrl);
$material->media_count = $mediaCount;
$material->download = $downloadUrl;
} else {
$url = $request->input('url', null);
if (!empty($url)) {
......
......@@ -85,8 +85,9 @@ class TechnicalNoteController extends Controller
$technicalNote->source = $request->input('source');
if ($request->hasFile('content')) {
$mediaCount = 1;
$downloadUrl = null;
$technicalNote->content = handle_module_upload($request->file('content'), $mediaCount);
$technicalNote->content = handle_module_upload($request->file('content'), $mediaCount, $downloadUrl);
}
if (is_admin($user) && $request->has('published')) {
$technicalNote->published = $request->input('published');
......
......@@ -96,8 +96,10 @@ class MaterialController extends Controller
}
if ($request->hasFile('file')) {
$mediaCount = 1;
$material->content = handle_module_upload($request->file('file'), $mediaCount);
$downloadUrl = null;
$material->content = handle_module_upload($request->file('file'), $mediaCount, $downloadUrl);
$material->media_count = $mediaCount;
$material->download = $downloadUrl;
} else {
$url = $request->input('url', null);
if (!empty($url)) {
......
......@@ -65,8 +65,9 @@ class TechnicalNoteController extends Controller
$technicalNote->source = $request->input('source');
if ($request->hasFile('content')) {
$mediaCount = 1;
$downloadUrl = null;
$technicalNote->content = handle_module_upload($request->file('content'), $mediaCount);
$technicalNote->content = handle_module_upload($request->file('content'), $mediaCount, $downloadUrl);
}
$technicalNote->published = $request->input('published');
......
......@@ -39,6 +39,7 @@ class Material extends JsonResource
'creator' => new SimpleUser($this->creator),
'type' => $this->type,
'url' => fix_url($this->url),
'download_url' => fix_url($this->download),
'recommend' => (int) $this->recommend,
'views' => (int) $this->views,
'favourites' => (int) $this->favourites,
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddDownloadFieldToMaterialsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('materials', function (Blueprint $table) {
$table->string('download')
->nullable()
->after('content');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('materials', function (Blueprint $table) {
$table->dropColumn('download');
});
}
}
......@@ -13,12 +13,13 @@ function handle_upload($file)
: Storage::disk('public')->url($path);
}
function handle_module_upload($file, &$mediaCount)
function handle_module_upload($file, &$mediaCount, &$downloadUrl)
{
$disk = Storage::disk('public');
$time = time();
$path = $disk->putFile(date('Ym', $time), $file);
$downloadUrl = $disk->url($path);
if (stripos($path, '.zip') !== false) {
$zip = new \ZipArchive;
......@@ -26,7 +27,7 @@ function handle_module_upload($file, &$mediaCount)
$zip->open($disk->path($path));
$zip->extractTo($disk->path(date('Ym', $time) . '/' . date('Ymd-His', $time)));
$zip->close();
$disk->delete($path);
// $disk->delete($path);
$filename = 'index.html';
if ($disk->exists(date('Ym', $time) . '/' . date('Ymd-His', $time) . '/topics.json')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment