Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 822 Rev 823
Línea 100... Línea 100...
100
     */
100
     */
101
    private $storagePath;
101
    private $storagePath;
Línea 102... Línea 102...
102
 
102
 
103
    /**
103
    /**
-
 
104
     *
-
 
105
     * @var string
-
 
106
     */
-
 
107
    private $fullStoragePath;
-
 
108
 
-
 
109
    /**
-
 
110
     *
-
 
111
     * @var array
-
 
112
     */
-
 
113
    private $storageConfig;
-
 
114
 
-
 
115
    /**
104
     *
116
     *
105
     * @var array
117
     * @var array
106
     */
118
     */
Línea 122... Línea 134...
122
    {
134
    {
123
        $this->config = $config;
135
        $this->config = $config;
124
        $this->adapter = $adapter;
136
        $this->adapter = $adapter;
125
        $this->currentFile = [];
137
        $this->currentFile = [];
Línea -... Línea 138...
-
 
138
 
-
 
139
        // Cargar configuración desde storage.ini
-
 
140
        $this->loadStorageConfig();
-
 
141
 
126
 
142
        // Ruta relativa para BD
-
 
143
        $this->storagePath = str_replace('\\', '/', $this->storageConfig['base_path']);
-
 
144
        
-
 
145
        // Ruta completa para operaciones de archivo
-
 
146
        $this->fullStoragePath = str_replace('\\', '/', $this->storageConfig['full_path']);
127
        $this->storagePath = 'data' . DIRECTORY_SEPARATOR . 'storage';
147
 
128
        if (!file_exists($this->storagePath)) {
148
        if (!file_exists($this->fullStoragePath)) {
129
            mkdir($this->storagePath, 0775, true);
149
            mkdir($this->fullStoragePath, 0775, true);
Línea 130... Línea 150...
130
        }
150
        }
Línea 131... Línea 151...
131
 
151
 
132
        $this->tempPath = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
152
        $this->tempPath = str_replace('\\', '/', $this->storageConfig['temp_path']);
133
 
153
 
134
        if (! file_exists($this->tempPath)) {
154
        if (! file_exists($this->tempPath)) {
Línea 155... Línea 175...
155
     *
175
     *
156
     * @return string
176
     * @return string
157
     */
177
     */
158
    public function getFullPathImageDefault()
178
    public function getFullPathImageDefault()
159
    {
179
    {
160
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image.jpg';
180
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image.jpg';
161
    }
181
    }
Línea 162... Línea 182...
162
 
182
 
163
    /**
183
    /**
164
     *
184
     *
165
     * @return string
185
     * @return string
166
     */
186
     */
167
    public function getFullPathImageUserDefault()
187
    public function getFullPathImageUserDefault()
168
    {
188
    {
169
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-user.jpg';
189
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-user.jpg';
Línea 170... Línea 190...
170
    }
190
    }
171
 
191
 
172
    /**
192
    /**
173
     *
193
     *
174
     * @return string
194
     * @return string
175
     */
195
     */
176
    public function getFullPathImageUserPofileDefault()
196
    public function getFullPathImageUserPofileDefault()
177
    {
197
    {
Línea 178... Línea 198...
178
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-user-profile.png';
198
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-user-profile.png';
179
    }
199
    }
180
 
200
 
181
    /**
201
    /**
182
     *
202
     *
183
     * @return string
203
     * @return string
184
     */
204
     */
185
    public function getFullPathImageUserCoverDefault()
205
    public function getFullPathImageUserCoverDefault()
Línea 186... Línea 206...
186
    {
206
    {
187
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
207
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
188
    }
208
    }
189
 
209
 
190
    /**
210
    /**
191
     *
211
     *
192
     * @return string
212
     * @return string
193
     */
213
     */
Línea 194... Línea 214...
194
    public function getFullPathImageCompanyDefault()
214
    public function getFullPathImageCompanyDefault()
195
    {
215
    {
196
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-company.jpg';
216
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-company.jpg';
197
    }
217
    }
198
 
218
 
199
    /**
219
    /**
200
     *
220
     *
201
     * @return string
221
     * @return string
Línea 202... Línea 222...
202
     */
222
     */
203
    public function getFullPathImageCompanyCoverDefault()
223
    public function getFullPathImageCompanyCoverDefault()
204
    {
224
    {
205
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
225
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
206
    }
226
    }
207
 
227
 
208
    /**
228
    /**
209
     *
229
     *
Línea 210... Línea 230...
210
     * @return string
230
     * @return string
211
     */
231
     */
212
    public function getFullPathImageGroupDefault()
232
    public function getFullPathImageGroupDefault()
213
    {
233
    {
214
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-group.jpg';
234
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-group.jpg';
215
    }
235
    }
216
 
236
 
217
    /**
237
    /**
Línea 218... Línea 238...
218
     *
238
     *
219
     * @return string
239
     * @return string
220
     */
240
     */
221
    public function getFullPathImageGroupCoverDefault()
241
    public function getFullPathImageGroupCoverDefault()
222
    {
242
    {
223
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
243
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
224
    }
244
    }
225
 
245
 
Línea 226... Línea 246...
226
    /**
246
    /**
227
     *
247
     *
228
     * @return string
248
     * @return string
229
     */
249
     */
230
    public function getFullPathImageCompanyHeaderPdfDefault()
250
    public function getFullPathImageCompanyHeaderPdfDefault()
231
    {
251
    {
232
        return $this->storagePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-header.png';
252
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-header.png';
-
 
253
    }
-
 
254
 
-
 
255
    /**
-
 
256
     *
-
 
257
     * @return string
-
 
258
     */
-
 
259
    public function getFullPathImageCompanyFooterPdfDefault()
-
 
260
    {
-
 
261
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-footer.png';
-
 
262
    }
-
 
263
 
-
 
264
    /**
-
 
265
     * Carga la configuración desde el archivo storage.ini
-
 
266
     */
-
 
267
    private function loadStorageConfig()
-
 
268
    {
-
 
269
        $iniPath = 'config' . DIRECTORY_SEPARATOR . 'storage.ini';
-
 
270
        if (file_exists($iniPath)) {
-
 
271
            $ini = parse_ini_file($iniPath, true);
-
 
272
            $this->storageConfig = [
-
 
273
                'base_path' => $ini['storage']['base_path'] ?? 'data/storage',
-
 
274
                'full_path' => $ini['storage']['full_path'] ?? 'data/storage',
-
 
275
                'base_url' => $ini['storage']['base_url'] ?? '',
-
 
276
                'temp_path' => $ini['temp']['temp_path'] ?? 'data/storage/tmp'
-
 
277
            ];
-
 
278
        } else {
-
 
279
            // Configuración por defecto si no existe el archivo .ini
-
 
280
            $this->storageConfig = [
-
 
281
                'base_path' => 'data/storage',
-
 
282
                'full_path' => 'data/storage',
-
 
283
                'base_url' => '',
-
 
284
                'temp_path' => 'data/storage/tmp'
-
 
285
            ];
-
 
286
        }
-
 
287
    }
-
 
288
 
-
 
289
    /**
-
 
290
     * Convierte una ruta relativa a ruta completa para operaciones de archivo
-
 
291
     * @param string $relativePath
-
 
292
     * @return string
-
 
293
     */
-
 
294
    private function getFullPathFromRelative($relativePath)
-
 
295
    {
-
 
296
        // Si la ruta ya es absoluta, la devolvemos tal como está
-
 
297
        if (strpos($relativePath, $this->fullStoragePath) === 0) {
-
 
298
            return $relativePath;
-
 
299
        }
-
 
300
        
-
 
301
        // Reemplazar la ruta base relativa con la ruta completa
-
 
302
        return str_replace($this->storagePath, $this->fullStoragePath, $relativePath);
-
 
303
    }
-
 
304
 
-
 
305
    /**
-
 
306
     * Convierte una ruta completa a ruta relativa para almacenar en BD
-
 
307
     * @param string $fullPath
-
 
308
     * @return string
-
 
309
     */
233
    }
310
    private function getRelativePathFromFull($fullPath)
Línea 234... Línea 311...
234
 
311
    {
235
    /**
312
        // Si ya es una ruta relativa, la devolvemos tal como está
236
     *
313
        if (strpos($fullPath, $this->fullStoragePath) !== 0) {
Línea 249... Línea 326...
249
    {
326
    {
250
        return $this->storagePath;
327
        return $this->storagePath;
251
    }
328
    }
Línea 252... Línea 329...
252
 
329
 
-
 
330
    /**
-
 
331
     * Obtiene la ruta completa para operaciones de archivo
-
 
332
     * @return string
-
 
333
     */
-
 
334
    public function getFullStoragePath()
-
 
335
    {
-
 
336
        return $this->fullStoragePath;
-
 
337
    }
-
 
338
 
253
    /**
339
    /**
254
     *
340
     *
255
     * @return string
341
     * @return string
256
     */
342
     */
257
    public function getTempPath()
343
    public function getTempPath()
Línea 327... Línea 413...
327
     */
413
     */
328
    public function composePathToFilename($type, $code, $filename)
414
    public function composePathToFilename($type, $code, $filename)
329
    {
415
    {
330
        $path = $this->getPathByType($type);
416
        $path = $this->getPathByType($type);
331
        $path = $path . DIRECTORY_SEPARATOR . $code;
417
        $path = $path . DIRECTORY_SEPARATOR . $code;
332
 
-
 
333
        $storageDir = $this->config['leaderslinked.storage.path'];
-
 
334
        $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $path;
-
 
335
 
-
 
336
        if (!file_exists($storageFileFullPath)) {
418
        if (!file_exists($path)) {
337
            mkdir($storageFileFullPath, 0775, true);
419
            mkdir($path, 0775, true);
338
        }
420
        }
339
 
-
 
340
        return $path . DIRECTORY_SEPARATOR . $filename;
421
        return $path . DIRECTORY_SEPARATOR . $filename;
341
    }
422
    }
Línea 342... Línea 423...
342
 
423
 
343
    /**
424
    /**
Línea 505... Línea 586...
505
 
586
 
506
        if (file_exists($remoto)) {
587
        if (file_exists($remoto)) {
507
            return $this->getPresignedUrl($remoto);
588
            return $this->getPresignedUrl($remoto);
Línea 508... Línea -...
508
        }
-
 
509
 
-
 
510
        $storageDir = $this->config['leaderslinked.storage.path'];
-
 
511
        $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $path;
-
 
512
        if (file_exists($storageFileFullPath)) {
-
 
513
            return $this->getPresignedUrl($storageFileFullPath);
-
 
514
        }
589
        }
515
 
590
 
516
        $remoto = $this->getFullPathImageDefault();
591
        $remoto = $this->getFullPathImageDefault();
Línea 517... Línea 592...
517
        return $this->getPresignedUrl($remoto);
592
        return $this->getPresignedUrl($remoto);
Línea 694... Línea 769...
694
 
769
 
695
    public function getPathByType($type)
770
    public function getPathByType($type)
696
    {
771
    {
697
        switch ($type) {
772
        switch ($type) {
698
            case self::TYPE_DEFAULT:
773
            case self::TYPE_DEFAULT:
699
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'default';
774
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default';
Línea 700... Línea 775...
700
                break;
775
                break;
701
 
776
 
702
            case self::TYPE_CHAT:
777
            case self::TYPE_CHAT:
Línea 703... Línea 778...
703
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'chat';
778
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'chat';
704
                break;
779
                break;
705
 
780
 
Línea 706... Línea 781...
706
            case self::TYPE_GROUP:
781
            case self::TYPE_GROUP:
707
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'group';
782
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'group';
708
                break;
783
                break;
Línea 709... Línea 784...
709
 
784
 
710
            case self::TYPE_USER:
785
            case self::TYPE_USER:
711
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'user';
786
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'user';
Línea 712... Línea 787...
712
                break;
787
                break;
713
 
788
 
714
            case self::TYPE_IMAGE:
789
            case self::TYPE_IMAGE:
Línea 715... Línea 790...
715
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'image';
790
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'image';
716
                break;
791
                break;
717
 
792
 
Línea 718... Línea 793...
718
            case self::TYPE_JOB:
793
            case self::TYPE_JOB:
719
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job';
794
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'job';
720
                break;
795
                break;
Línea 721... Línea 796...
721
 
796
 
722
            case self::TYPE_COMPANY:
797
            case self::TYPE_COMPANY:
723
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'company';
798
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'company';
Línea 724... Línea 799...
724
                break;
799
                break;
725
 
800
 
726
            case self::TYPE_FEED:
801
            case self::TYPE_FEED:
Línea 727... Línea 802...
727
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'feed';
802
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'feed';
728
                break;
803
                break;
729
 
804
 
Línea 730... Línea 805...
730
            case self::TYPE_MEDIA:
805
            case self::TYPE_MEDIA:
731
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'media';
806
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'media';
732
                break;
807
                break;
Línea 733... Línea 808...
733
 
808
 
734
            case self::TYPE_POST:
809
            case self::TYPE_POST:
735
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'post';
810
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'post';
Línea 736... Línea 811...
736
                break;
811
                break;
737
 
812
 
738
            case self::TYPE_MICROLEARNING_TOPIC:
813
            case self::TYPE_MICROLEARNING_TOPIC:
Línea 739... Línea 814...
739
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'topic';
814
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'topic';
740
                break;
815
                break;
741
 
816
 
Línea 742... Línea 817...
742
            case self::TYPE_MICROLEARNING_CAPSULE:
817
            case self::TYPE_MICROLEARNING_CAPSULE:
743
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'capsule';
818
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'capsule';
744
                break;
819
                break;
Línea 745... Línea 820...
745
 
820
 
746
            case self::TYPE_MICROLEARNING_SLIDE:
821
            case self::TYPE_MICROLEARNING_SLIDE:
747
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'slide';
822
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'slide';
Línea 748... Línea 823...
748
                break;
823
                break;
749
 
824
 
750
            case self::TYPE_JOB_DESCRIPTION:
825
            case self::TYPE_JOB_DESCRIPTION:
Línea 751... Línea 826...
751
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job-description';
826
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'job-description';
752
                break;
827
                break;
753
 
828
 
Línea 754... Línea 829...
754
            case self::TYPE_SELF_EVALUATION:
829
            case self::TYPE_SELF_EVALUATION:
755
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'self-evaluation';
830
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'self-evaluation';
756
                break;
831
                break;
Línea 757... Línea 832...
757
 
832
 
758
            case self::TYPE_PERFORMANCE_EVALUATION:
833
            case self::TYPE_PERFORMANCE_EVALUATION:
759
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'performance-evaluation';
834
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'performance-evaluation';
Línea 760... Línea 835...
760
                break;
835
                break;
761
 
836
 
762
            case self::TYPE_RECRUITMENT_SELECTION:
837
            case self::TYPE_RECRUITMENT_SELECTION:
Línea 763... Línea 838...
763
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'recruitment-selection';
838
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'recruitment-selection';
764
                break;
839
                break;
765
 
840
 
Línea 766... Línea 841...
766
            case self::TYPE_PLANNING_OBJECTIVES_AND_GOALS:
841
            case self::TYPE_PLANNING_OBJECTIVES_AND_GOALS:
767
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'planning-objectives-and-goals';
842
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'planning-objectives-and-goals';
768
                break;
843
                break;
Línea 769... Línea 844...
769
 
844
 
770
            case self::TYPE_MESSAGE:
845
            case self::TYPE_MESSAGE:
771
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'message';
846
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'message';
Línea 772... Línea 847...
772
                break;
847
                break;
773
 
848
 
774
            case self::TYPE_SURVEY:
849
            case self::TYPE_SURVEY:
Línea 775... Línea 850...
775
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'survey';
850
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'survey';
776
                break;
851
                break;
777
 
852
 
Línea 778... Línea 853...
778
            case self::TYPE_NETWORK:
853
            case self::TYPE_NETWORK:
779
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'network';
854
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'network';
780
                break;
855
                break;
781
 
856
 
Línea 782... Línea 857...
782
            case self::TYPE_DAILY_PULSE:
857
            case self::TYPE_DAILY_PULSE:
783
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'daily-pulse';
858
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'daily-pulse';
Línea 916... Línea 991...
916
     * @param string $url
991
     * @param string $url
917
     * @return string
992
     * @return string
918
     */
993
     */
919
    public function getPresignedUrl($url)
994
    public function getPresignedUrl($url)
920
    {
995
    {
-
 
996
        // Convertir la ruta completa a ruta relativa para almacenar en BD
-
 
997
        $relativePath = $this->getRelativePathFromFull($url);
921
        $code = hash('sha256', $url);
998
        $code = hash('sha256', $url);
Línea 922... Línea 999...
922
 
999
 
923
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
1000
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
924
        $storageFile = $storageFileMapper->fetchOneByCode($code);
1001
        $storageFile = $storageFileMapper->fetchOneByCode($code);
925
        if (! $storageFile) {
1002
        if (! $storageFile) {
926
            $storageFile = new \LeadersLinked\Model\StorageFile();
1003
            $storageFile = new \LeadersLinked\Model\StorageFile();
-
 
1004
            $storageFile->code = $code;
927
            $storageFile->code = $code;
1005
            // Guardar la ruta relativa en la base de datos
928
            $storageFile->path = $url;
1006
            $storageFile->path = $relativePath;
Línea 929... Línea -...
929
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
-
 
930
 
-
 
931
 
1007
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
932
 
1008
 
Línea 933... Línea -...
933
            $storageFileMapper->insert($storageFile);
-
 
934
        }
1009
            $storageFileMapper->insert($storageFile);
Línea 935... Línea 1010...
935
 
1010
        }
936
 
1011
 
Línea 937... Línea 1012...
937
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
1012
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
-
 
1013
 
-
 
1014
        return $url;
-
 
1015
    }
-
 
1016
 
-
 
1017
    /**
-
 
1018
     * Obtiene la ruta completa del archivo basado en el código almacenado
-
 
1019
     * @param string $code
-
 
1020
     * @return string|null
-
 
1021
     */
-
 
1022
    public function getFilePathByCode($code)
-
 
1023
    {
-
 
1024
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
-
 
1025
        $storageFile = $storageFileMapper->fetchOneByCode($code);
-
 
1026
        
-
 
1027
        if ($storageFile && $storageFile->path) {
-
 
1028
            // Convertir la ruta relativa almacenada en BD a ruta completa
-
 
1029
            return $this->getFullPathFromRelative($storageFile->path);
-
 
1030
        }
-
 
1031
        
-
 
1032
        return null;
-
 
1033
    }
-
 
1034
 
-
 
1035
    /**
-
 
1036
     * Verifica si un archivo existe usando el código almacenado
-
 
1037
     * @param string $code
-
 
1038
     * @return bool
-
 
1039
     */
-
 
1040
    public function fileExistsByCode($code)
-
 
1041
    {
938
 
1042
        $filePath = $this->getFilePathByCode($code);
939
        return $url;
1043
        return $filePath && file_exists($filePath);
940
    }
1044
    }
941
 
1045
 
942
    /**
1046
    /**
Línea 1050... Línea 1154...
1050
     * @param string $sourceFilenameToUnlink The path to the source file to unlink.
1154
     * @param string $sourceFilenameToUnlink The path to the source file to unlink.
1051
     * @return bool True on success, false on failure.
1155
     * @return bool True on success, false on failure.
1052
     */
1156
     */
1053
    private function _savePngAndCleanup($imageResource, $targetFilename, $sourceFilenameToUnlink)
1157
    private function _savePngAndCleanup($imageResource, $targetFilename, $sourceFilenameToUnlink)
1054
    {
1158
    {
1055
        $storageDir = $this->config['leaderslinked.storage.path'];
-
 
1056
        $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $targetFilename;
-
 
1057
 
-
 
1058
        $save_success = imagepng($imageResource, $storageFileFullPath);
1159
        $save_success = imagepng($imageResource, $targetFilename);
1059
        imagedestroy($imageResource); // Clean up the image resource
1160
        imagedestroy($imageResource); // Clean up the image resource
Línea 1060... Línea 1161...
1060
 
1161
 
1061
        if ($save_success) {
1162
        if ($save_success) {
1062
            if ($sourceFilenameToUnlink && file_exists($sourceFilenameToUnlink)) {
1163
            if ($sourceFilenameToUnlink && file_exists($sourceFilenameToUnlink)) {
1063
                unlink($sourceFilenameToUnlink);
1164
                unlink($sourceFilenameToUnlink);
1064
            }
1165
            }
1065
            return true;
1166
            return true;
1066
        } else {
1167
        } else {
1067
            error_log("_savePngAndCleanup: imagepng failed to save image to {$storageFileFullPath}.");
1168
            error_log("_savePngAndCleanup: imagepng failed to save image to {$targetFilename}.");
1068
            return false;
1169
            return false;
1069
        }
1170
        }
Línea 1070... Línea 1171...
1070
    }
1171
    }