Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17018 | Rev 17275 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17018 Rev 17274
Línea 14... Línea 14...
14
use LeadersLinked\Mapper\PostMapper;
14
use LeadersLinked\Mapper\PostMapper;
15
use LeadersLinked\Form\Post\PostCreateForm;
15
use LeadersLinked\Form\Post\PostCreateForm;
16
use LeadersLinked\Form\Post\PostEditForm;
16
use LeadersLinked\Form\Post\PostEditForm;
17
use LeadersLinked\Model\Post;
17
use LeadersLinked\Model\Post;
18
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
18
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
19
use LeadersLinked\Library\Image;
19
use LeadersLinked\Library\Storage;
Línea 20... Línea 20...
20
 
20
 
21
class PostController extends AbstractActionController
21
class PostController extends AbstractActionController
22
{
22
{
23
    /**
23
    /**
Línea 174... Línea 174...
174
 
174
 
175
 
175
 
-
 
176
 
-
 
177
    public function addAction()
176
 
178
    {
177
    public function addAction()
179
        try {
178
    {
180
            $request    = $this->getRequest();
179
 
181
    
-
 
182
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
183
            $currentUser = $currentUserPlugin->getUser();
180
        $currentUserPlugin = $this->plugin('currentUserPlugin');
184
    
-
 
185
            if(!$currentUser->is_admin) {
-
 
186
                return new JsonModel([
-
 
187
                    'success' => false,
-
 
188
                    'data' => 'ERROR_NOT_AUTHORIZED'
181
        $currentUser = $currentUserPlugin->getUser();
189
                ]);
-
 
190
            }
-
 
191
    
-
 
192
            if (!$request->isPost()) {
-
 
193
                return new JsonModel([
-
 
194
                    'success' => false,
182
 
195
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
183
        $request    = $this->getRequest();
196
                ]);
184
        if ($request->isPost()) {
197
            }
185
 
-
 
186
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
198
    
187
            $dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
199
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
188
 
200
            $dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
189
 
201
    
190
            $form = new PostCreateForm();
202
            $form = new PostCreateForm();
191
            $form->setData($dataPost);
-
 
192
 
-
 
193
            if ($form->isValid()) {
-
 
194
                $dataPost = (array) $form->getData();
-
 
195
 
-
 
196
                $hydrator = new ObjectPropertyHydrator();
-
 
197
                $post = new Post();
-
 
198
                $hydrator->hydrate($dataPost, $post);
-
 
199
 
-
 
200
 
-
 
201
                $dt = \DateTime::createFromFormat('d/m/Y', $post->date);
-
 
202
                $post->date = $dt->format('Y-m-d');
-
 
203
                $post->network_id = $currentUser->network_id;
-
 
204
                $post->image = '';
-
 
205
                $post->file  = '';
-
 
206
                $post->user_id = $currentUser->id;
-
 
207
 
-
 
208
 
-
 
209
                $postMapper = PostMapper::getInstance($this->adapter);
-
 
210
                if ($postMapper->insert($post)) {
-
 
211
                    $post = $postMapper->fetchOne($post->id);
-
 
212
 
-
 
213
 
-
 
214
                    $files = $this->getRequest()->getFiles()->toArray();
-
 
215
 
-
 
216
                    $image = Image::getInstance($this->config);
-
 
217
                    $target_path = $image->getStorage()->getPathPost();
-
 
218
 
-
 
219
 
-
 
220
                    if (isset($files['file']) && empty($files['file']['error'])) {
-
 
221
                        $tmp_filename       = $files['file']['tmp_name'];
-
 
222
                        $original_filename  = trim(strtolower($files['file']['name']));
-
 
223
 
-
 
224
                        $original_filename = Functions::normalizeString($original_filename);
-
 
225
 
-
 
226
                        $parts = explode('.', $original_filename);
-
 
227
                        $filename = $parts[0] . '.' . $parts[count($parts) - 1];
-
 
228
 
-
 
229
                        $full_filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
-
 
230
                        move_uploaded_file($tmp_filename, $full_filename);
-
 
231
                        
-
 
232
                        
-
 
233
                        try {
-
 
234
                            if ($image->getStorage()->putFile($target_path, $post->uuid, $full_filename)) {
-
 
235
                                $post->file = $original_filename;
-
 
236
                                $post->update($post);
-
 
237
                            }
-
 
238
                        } catch (\Throwable $e) {
-
 
239
                            error_log($e->getTraceAsString());
-
 
240
                        }
-
 
241
                    }
-
 
242
 
-
 
243
                    if (isset($files['image']) && empty($files['image']['error'])) {
-
 
244
                        $tmp_filename  = $files['image']['tmp_name'];
-
 
245
 
-
 
246
                        try {
-
 
247
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
-
 
248
 
-
 
249
                            $filename = 'image-' . uniqid() . '.png';
-
 
250
                            $crop_to_dimensions = false;
-
 
251
                            $unlink_source = true;
-
 
252
                            
-
 
253
                            if($image->uploadProcessChangeSize($tmp_filename, $target_path, $post->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) { 
-
 
254
                                $post->image = $filename;
-
 
255
                                $postMapper->update($post);
-
 
256
                            }
-
 
257
                        } catch (\Throwable $e) {
-
 
258
                            error_log($e->getTraceAsString());
-
 
259
                        }
-
 
260
                    }
-
 
261
 
-
 
262
                    $this->logger->info('Se agrego la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
263
 
-
 
264
                    $data = [
-
 
265
                        'success'   => true,
-
 
266
                        'data'   => 'LABEL_RECORD_ADDED'
-
 
267
                    ];
-
 
268
                } else {
-
 
269
                    $data = [
-
 
270
                        'success'   => false,
-
 
271
                        'data'      => $postMapper->getError()
-
 
272
                    ];
-
 
273
                }
-
 
274
 
203
            $form->setData($dataPost);
275
                return new JsonModel($data);
204
    
276
            } else {
205
            if (!$form->isValid()) {
277
                $messages = [];
-
 
-
 
206
                $messages = [];
278
                $form_messages = (array) $form->getMessages();
207
                $form_messages = (array) $form->getMessages();
279
                foreach ($form_messages  as $fieldname => $field_messages) {
208
                foreach ($form_messages  as $fieldname => $field_messages) 
280
 
-
 
281
                    $messages[$fieldname] = array_values($field_messages);
209
                {
282
                }
210
                    $messages[$fieldname] = array_values($field_messages);
283
 
211
                }
284
                return new JsonModel([
212
                return new JsonModel([
285
                    'success'   => false,
213
                    'success'   => false,
-
 
214
                    'data'   => $messages
-
 
215
                ]);
-
 
216
            }
-
 
217
    
-
 
218
            $dataPost = (array) $form->getData();
-
 
219
    
-
 
220
            $hydrator = new ObjectPropertyHydrator();
-
 
221
            $post = new Post();
-
 
222
            $hydrator->hydrate($dataPost, $post);
-
 
223
    
-
 
224
            $dt = \DateTime::createFromFormat('d/m/Y', $post->date);
-
 
225
            $post->date = $dt->format('Y-m-d');
-
 
226
            $post->network_id = $currentUser->network_id;
-
 
227
            $post->image = '';
-
 
228
            $post->file  = '';
-
 
229
            $post->user_id = $currentUser->id;
-
 
230
    
-
 
231
            $postMapper = PostMapper::getInstance($this->adapter);
-
 
232
    
-
 
233
            if (!$postMapper->insert($post)) {
-
 
234
                return new JsonModel([
-
 
235
                    'success'   => false,
-
 
236
                    'data'   => $postMapper->getError()
-
 
237
                ]);
-
 
238
            }
-
 
239
    
-
 
240
            $storage = Storage::getInstance($this->config, $this->adapter);
-
 
241
    
-
 
242
            $storage->setFiles($request->getFiles()->toArray());
-
 
243
    
-
 
244
            if(!$storage->setCurrentFile('file')) {
-
 
245
                return new JsonModel([
286
                    'data'   => $messages
246
                    'success'   => false,
-
 
247
                    'data'   => 'ERROR_FILE_NOT_FOUND'
-
 
248
                ]);
-
 
249
            }
-
 
250
    
-
 
251
            $tmp_filename =  $storage->getTmpFilename();
-
 
252
            $filename = 'post-' . uniqid() . '.' . $storage->getExtension();
-
 
253
            $target_filename = $storage->composePathToFilename(
-
 
254
                Storage::TYPE_POST,
-
 
255
                $post->uuid,
-
 
256
                $filename
-
 
257
            );
-
 
258
    
-
 
259
            if(!$storage->putFile($tmp_filename, $target_filename)) {
287
                ]);
260
                return new JsonModel([
-
 
261
                    'success'   => false,
-
 
262
                    'data'   => 'ERROR_UPLOAD_FILE'
-
 
263
                ]);
-
 
264
            }
288
            }
265
            
289
        } else {
266
            if(!$storage->setCurrentFile('image')) {
-
 
267
                return new JsonModel([
-
 
268
                    'success'   => false,
-
 
269
                    'data'   => 'ERROR_FILE_NOT_FOUND'
-
 
270
                ]);
-
 
271
            }
-
 
272
    
-
 
273
     
-
 
274
            $tmp_filename  = $storage->getTmpFilename();
-
 
275
            $filename = 'post-image-' . uniqid() . '.png';
-
 
276
            $target_filename = $storage->composePathToFilename(
290
            $data = [
277
                Storage::TYPE_POST,
-
 
278
                $post->uuid,
-
 
279
                $filename
-
 
280
            );
-
 
281
    
-
 
282
            $post->file = $filename;
-
 
283
            
-
 
284
            if(!$storage->uploadImageWithOutChangeSize($tmp_filename, $target_filename)) {
-
 
285
                return new JsonModel([
-
 
286
                    'success'   => false,
-
 
287
                    'data'   => 'ERROR_UPLOAD_IMAGE'
-
 
288
                ]);
-
 
289
            }
-
 
290
            
-
 
291
            $post->image = $filename;
-
 
292
            
-
 
293
            if(!$postMapper->update($post)) {
-
 
294
                return new JsonModel([
-
 
295
                    'success'   => false,
-
 
296
                    'data'   => $postMapper->getError()
-
 
297
                ]);
291
                'success' => false,
298
            }
-
 
299
    
-
 
300
            $this->logger->info('Se agrego la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
301
    
-
 
302
            return new JsonModel([
-
 
303
                'success' => true,
-
 
304
                'data'   => 'LABEL_RECORD_ADDED'
292
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
305
            ]);
-
 
306
        } catch (\Throwable $e) {
-
 
307
            $this->logger->error('Error al agregar la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP(), 'error' => $e->getTraceAsString()]);
-
 
308
            return new JsonModel([
293
            ];
309
                'success'   => false,
294
 
-
 
295
            return new JsonModel($data);
-
 
296
        }
310
                'data'   => $e->getMessage()
Línea 297... Línea 311...
297
 
311
            ]);
298
        return new JsonModel($data);
312
        }
299
    }
313
    }
300
 
314
 
301
    /**
315
    /**
302
     *
316
     *
303
     * Borrar un perfil excepto el público
317
     * Borrar un perfil excepto el público
304
     * @return \Laminas\View\Model\JsonModel
318
     * @return \Laminas\View\Model\JsonModel
305
     */
319
     */
306
    public function deleteAction()
320
    public function deleteAction()
307
    {
321
    {
308
        $currentUserPlugin = $this->plugin('currentUserPlugin');
322
        try {
309
        $currentUser = $currentUserPlugin->getUser();
-
 
Línea -... Línea 323...
-
 
323
            $request    = $this->getRequest();
Línea 310... Línea 324...
310
 
324
            
-
 
325
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
326
            $currentUser = $currentUserPlugin->getUser();
311
        $request    = $this->getRequest();
327
 
-
 
328
            $id = $this->params()->fromRoute('id');
-
 
329
 
Línea 312... Línea 330...
312
        $id = $this->params()->fromRoute('id');
330
            if(!$currentUser->is_admin) {
313
 
331
                return new JsonModel([
314
 
332
                    'success' => false,
315
 
333
                    'data' => 'ERROR_NOT_AUTHORIZED'
316
        $postMapper = PostMapper::getInstance($this->adapter);
334
                ]);
317
        $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
335
            }
Línea -... Línea 336...
-
 
336
 
-
 
337
            if (!$request->isPost()) {
Línea 318... Línea 338...
318
 
338
                return new JsonModel([
-
 
339
                    'success' => false,
-
 
340
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
341
                ]);
-
 
342
            }
-
 
343
 
Línea 319... Línea 344...
319
        if (!$post) {
344
            $postMapper = PostMapper::getInstance($this->adapter);
Línea 320... Línea 345...
320
            return new JsonModel([
345
            $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
321
                'success' => false,
346
 
322
                'data' => 'ERROR_POST_NOT_FOUND'
-
 
323
            ]);
-
 
324
        }
-
 
325
 
-
 
326
 
-
 
Línea -... Línea 347...
-
 
347
            if (!$post) {
-
 
348
                return new JsonModel([
-
 
349
                    'success' => false,
-
 
350
                    'data' => 'ERROR_POST_NOT_FOUND'
-
 
351
                ]);
-
 
352
            }
Línea 327... Línea -...
327
        if ($request->isPost()) {
-
 
328
 
353
 
329
            $post->status = Post::STATUS_DELETE;
-
 
330
 
-
 
331
            $result =  $postMapper->update($post);
-
 
332
            if ($result) {
-
 
333
                
354
            $post->status = Post::STATUS_DELETE;
334
                
355
 
335
                
356
            $storage = Storage::getInstance($this->config, $this->adapter);
336
                
357
            $post_path = $storage->getPathPost();
-
 
358
 
Línea 337... Línea -...
337
                $this->logger->info('Se borro la noticia : ' .  $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
338
 
-
 
339
 
-
 
340
                $data = [
-
 
341
                    'success' => true,
-
 
342
                    'data' => 'LABEL_POST_DELETED'
359
            if($post->file) {
343
                ];
-
 
Línea 344... Línea 360...
344
            } else {
360
                $storage->deleteFile($post_path, $post->uuid, $post->file);
-
 
361
            }
-
 
362
            if($post->image) {
-
 
363
                $storage->deleteFile($post_path, $post->uuid, $post->image);
-
 
364
            }
-
 
365
 
-
 
366
            if(!$postMapper->update($post)) {
-
 
367
                return new JsonModel([
-
 
368
                    'success'   => false,
-
 
369
                    'data'   => $postMapper->getError()
345
 
370
                ]);
346
                $data = [
-
 
347
                    'success'   => false,
-
 
348
                    'data'      => $postMapper->getError()
371
            }   
Línea 349... Línea 372...
349
                ];
372
 
350
 
373
            $this->logger->info('Se borro la noticia : ' .  $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
351
                return new JsonModel($data);
374
 
352
            }
375
            return new JsonModel([
Línea 353... Línea 376...
353
        } else {
376
                'success' => true,
354
            $data = [
377
                'data' => 'LABEL_POST_DELETED'
Línea 355... Línea 378...
355
                'success' => false,
378
            ]);
356
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
Línea 357... Línea 379...
357
            ];
379
        } catch (\Throwable $th) {
358
 
380
            $this->logger->error('Error al borrar la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP(), 'error' => $th->getTraceAsString()]);
359
            return new JsonModel($data);
381
            return new JsonModel([
360
        }
382
                'success'   => false,
361
 
383
                'data'   => $th->getMessage()
362
        return new JsonModel($data);
384
            ]);
363
    }
-
 
364
 
-
 
365
 
-
 
Línea 366... Línea 385...
366
    public function editAction()
385
        }
-
 
386
    }
-
 
387
 
-
 
388
 
-
 
389
    public function editAction()
-
 
390
    {
Línea 367... Línea -...
367
    {
-
 
368
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
369
        $currentUser = $currentUserPlugin->getUser();
-
 
370
 
-
 
371
        $request    = $this->getRequest();
391
        try {
372
        $id = $this->params()->fromRoute('id');
392
            $request    = $this->getRequest();
373
 
-
 
374
        $postMapper = PostMapper::getInstance($this->adapter);
-
 
375
        $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
376
 
-
 
Línea -... Línea 393...
-
 
393
 
377
        if (!$post) {
394
            $currentUserPlugin = $this->plugin('currentUserPlugin');
378
            return new JsonModel([
395
            $currentUser = $currentUserPlugin->getUser();
379
                'success' => false,
396
 
380
                'data' => 'ERROR_POST_NOT_FOUND'
397
            $id = $this->params()->fromRoute('id');
-
 
398
 
Línea 381... Línea -...
381
            ]);
-
 
382
        }
-
 
Línea -... Línea 399...
-
 
399
            if(!$currentUser->is_admin) {
-
 
400
                return new JsonModel([
-
 
401
                    'success' => false,
-
 
402
                    'data' => 'ERROR_NOT_AUTHORIZED'
-
 
403
                ]);
-
 
404
            }
-
 
405
 
-
 
406
            if (!$request->isPost() && !$request->isGet()) {
-
 
407
                return new JsonModel([
-
 
408
                    'success' => false,
-
 
409
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
410
                ]);
-
 
411
            }
-
 
412
 
-
 
413
            $postMapper = PostMapper::getInstance($this->adapter);
-
 
414
            $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
415
 
-
 
416
            if (!$post) {
-
 
417
                return new JsonModel([
-
 
418
                    'success' => false,
-
 
419
                    'data' => 'ERROR_POST_NOT_FOUND'
383
 
420
                ]);
-
 
421
            }
-
 
422
 
-
 
423
 
-
 
424
            if ($request->isGet()) {
-
 
425
                $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
-
 
426
                return new JsonModel([
-
 
427
                    'success' => true,
-
 
428
                    'data' => [
-
 
429
                        'title' => $post->title,
-
 
430
                        'status' => $post->status,
-
 
431
                        'description' => $post->description,
-
 
432
                        'url' => $post->url,
384
 
433
                        'date' => $dt->format('d/m/Y'),
Línea 385... Línea -...
385
        if ($request->isGet()) {
-
 
386
 
434
                    ]
387
            $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
435
                ]);
388
 
436
            } 
389
            $data = [
437
            
Línea 390... Línea 438...
390
                'success' => true,
438
            if ($request->isPost()) {
391
                'data' => [
439
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
Línea -... Línea 440...
-
 
440
                $dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
-
 
441
 
Línea -... Línea 442...
-
 
442
                $form = new PostEditForm();
Línea -... Línea 443...
-
 
443
                $form->setData($dataPost);
-
 
444
 
-
 
445
                if (!$form->isValid()) {
-
 
446
                    $messages = [];
-
 
447
                    $form_messages = (array) $form->getMessages();
-
 
448
                    foreach ($form_messages  as $fieldname => $field_messages) 
-
 
449
                    {
-
 
450
                        $messages[$fieldname] = array_values($field_messages);
Línea 392... Línea -...
392
                    'title' => $post->title,
-
 
393
                    'status' => $post->status,
-
 
394
                    'description' => $post->description,
-
 
395
                    'url' => $post->url,
-
 
396
                    'date' => $dt->format('d/m/Y'),
-
 
397
                ]
-
 
398
            ];
-
 
399
 
-
 
400
            return new JsonModel($data);
451
                    }
401
        } else if ($request->isPost()) {
452
                    return new JsonModel([
402
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
453
                        'success'   => false,
Línea 403... Línea -...
403
            $dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
-
 
404
 
-
 
405
            $form = new PostEditForm();
-
 
406
            $form->setData($dataPost);
-
 
407
 
-
 
408
            if ($form->isValid()) {
-
 
409
                $dataPost = (array) $form->getData();
-
 
410
 
-
 
411
 
-
 
412
                $post->title        = $dataPost['title'];
-
 
413
                $post->description  = $dataPost['description'];
-
 
414
                $post->url          = isset($dataPost['url']) ? $dataPost['url'] : '';
454
                        'data'   => $messages
415
                $post->status       = isset($dataPost['status']) ? $dataPost['status'] : Post::STATUS_INACTIVE;
-
 
416
 
-
 
417
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['date']);
455
                    ]);
418
                $post->date = $dt->format('Y-m-d');
-
 
419
 
456
                }
420
 
457
                
421
 
458
                $dataPost = (array) $form->getData();
422
 
-
 
423
                $files = $this->getRequest()->getFiles()->toArray();
-
 
424
 
459
 
-
 
460
                $post->title        = $dataPost['title'];
-
 
461
                $post->description  = $dataPost['description'];
425
                $image = Image::getInstance($this->config);
462
                $post->url          = isset($dataPost['url']) ? $dataPost['url'] : '';
Línea 426... Línea 463...
426
                $target_path = $image->getStorage()->getPathPost();
463
                $post->status       = isset($dataPost['status']) ? $dataPost['status'] : Post::STATUS_INACTIVE;
-
 
464
 
-
 
465
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['date']);
-
 
466
                $post->date = $dt->format('Y-m-d');
-
 
467
 
-
 
468
                $storage = Storage::getInstance($this->config, $this->adapter);
-
 
469
                $post_path = $storage->getPathPost();
-
 
470
 
Línea 427... Línea 471...
427
 
471
                $storage->setFiles($request->getFiles()->toArray());
428
 
472
 
429
                if (isset($files['file']) && empty($files['file']['error'])) {
473
                if($storage->setCurrentFile('file')) {
Línea 430... Línea -...
430
 
-
 
431
                    if ($post->file) {
-
 
432
                        $image->getStorage()->deleteFile($target_path, $post->uuid, $post->file);
-
 
433
                    }
-
 
434
 
474
                    $tmp_filename =  $storage->getTmpFilename();
435
 
-
 
436
                    $tmp_filename       = $files['file']['tmp_name'];
-
 
437
                    $original_filename  = trim(strtolower($files['file']['name']));
475
                    $filename = 'post-' . uniqid() . '.' . $storage->getExtension();
438
 
476
                    $target_filename = $storage->composePathToFilename(
439
                    $original_filename = Functions::normalizeString($original_filename);
-
 
440
 
-
 
441
                    $parts = explode('.', $original_filename);
-
 
442
                    $filename = $parts[0] . '.' . $parts[count($parts) - 1];
-
 
443
                   
-
 
444
                   
477
                        Storage::TYPE_POST,
445
                    $full_filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
478
                        $post->uuid,
446
                    move_uploaded_file($tmp_filename, $full_filename);
-
 
447
                    
-
 
448
                    
479
                        $filename
449
                    try {
-
 
450
                        if ($image->getStorage()->putFile($target_path, $post->uuid, $full_filename)) {
-
 
Línea -... Línea 480...
-
 
480
                    );
-
 
481
 
Línea 451... Línea 482...
451
                            $post->file = basename($filename);
482
                    if($post->file) {
452
                            $post->update($post);
-
 
453
                        }
-
 
454
                    } catch (\Throwable $e) {
-
 
455
                        error_log($e->getTraceAsString());
-
 
456
                    }
-
 
457
                }
-
 
458
 
-
 
459
                if (isset($files['image']) && empty($files['image']['error'])) {
483
                        $storage->deleteFile($post_path, $post->uuid, $post->file);
460
 
484
                    }
461
                    if ($post->image) {
485
 
462
                        $image->getStorage()->deleteFile($target_path, $post->uuid, $post->image);
486
                    if(!$storage->putFile($tmp_filename, $target_filename)) {
463
                    }
487
                        return new JsonModel([
Línea 464... Línea -...
464
 
-
 
465
 
-
 
466
                    $tmp_filename  = $files['image']['tmp_name'];
-
 
467
 
-
 
468
                    try {
488
                            'success'   => false,
469
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
-
 
470
 
-
 
471
                        $filename = 'image-' . uniqid() . '.png';
-
 
Línea 472... Línea 489...
472
                        $crop_to_dimensions = true;
489
                            'data'   => 'ERROR_UPLOAD_FILE'
473
                        $unlink_source = false;
490
                        ]);
474
                        
491
                    }
475
                        
492
 
476
                        if ($image->uploadProcessChangeSize($tmp_filename, $target_path, $post->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) { 
493
                    $post->file = $filename;
477
            
494
                }
-
 
495
 
478
                            $post->image = $filename;
496
                if($storage->setCurrentFile('image')) {
479
                            $postMapper->update($post);
497
                    $tmp_filename =  $storage->getTmpFilename();
480
                        }
498
                    $filename = 'post-image-' . uniqid() . '.png';
481
                    } catch (\Throwable $e) {
499
                    $target_filename = $storage->composePathToFilename(
482
                        error_log($e->getTraceAsString());
-
 
483
                    }
-
 
484
                }
500
                        Storage::TYPE_POST,
485
 
-
 
486
 
-
 
487
 
501
                        $post->uuid,
488
                if ($postMapper->update($post)) {
502
                        $filename