ValidateLoadArchivesController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Validator;
  5. use Illuminate\Support\Facades\DB;
  6. use PhpOffice\PhpSpreadsheet\IOFactory;
  7. use ZipArchive;
  8. /**
  9. * Controller for validating Excel and ZIP files for equipment documentation loading
  10. * Validates Excel headers structure and compares file listings with ZIP contents
  11. */
  12. class ValidateLoadArchivesController extends Controller
  13. {
  14. private $responseController;
  15. private $encryptionController;
  16. private $documentManagementController;
  17. // Expected headers in row 7 of Excel file with their corresponding column letters
  18. private $expectedHeaders = [
  19. ['letter' => 'D', 'category' => 'CÓDIGO DE EQUIPO'],
  20. ['letter' => 'H', 'category' => 'FICHA DE SEGURIDAD DE PRODUCTOS QUÍMICOS'],
  21. ['letter' => 'J', 'category' => 'FICHA TÉCNICA'],
  22. ['letter' => 'L', 'category' => 'FOTOGRAFÍAS - DIAGRAMAS'],
  23. ['letter' => 'N', 'category' => 'DATOS DEL PROVEEDOR'],
  24. ['letter' => 'P', 'category' => 'MANUALES DE OPERACIÓN'],
  25. ['letter' => 'R', 'category' => 'MANUALES DE MANTENIMIENTO PREVENTIVO'],
  26. ['letter' => 'T', 'category' => 'MANUALES DE MANTENIMIENTO CORRECTIVO'],
  27. ['letter' => 'V', 'category' => 'DOCUMENTOS ADICIONALES']
  28. ];
  29. // Mapping of file extensions to their types for validation
  30. private $extensionTypes = [
  31. // Archivos de almacenamiento
  32. 'zip' => 'STORAGE', 'rar' => 'STORAGE', 'tar' => 'STORAGE', '7z' => 'STORAGE',
  33. // Formatos de audio
  34. 'mp3' => 'AUDIO', 'mpeg' => 'AUDIO', 'wav' => 'AUDIO', 'ogg' => 'AUDIO', 'opus' => 'AUDIO',
  35. // Archivos de imagen
  36. 'jpeg' => 'IMG', 'jpg' => 'IMG', 'png' => 'IMG', 'gif' => 'IMG', 'bmp' => 'IMG', 'tiff' => 'IMG', 'svg' => 'IMG',
  37. // Archivos de texto
  38. 'txt' => 'TEXT',
  39. // Archivos de video
  40. 'webm' => 'VIDEO', 'mpeg4' => 'VIDEO', 'mp4' => 'VIDEO', '3gpp' => 'VIDEO', 'mov' => 'VIDEO', 'avi' => 'VIDEO', 'wmv' => 'VIDEO', 'flv' => 'VIDEO',
  41. // Planos de Auto CAD
  42. 'dwg' => 'CAD', 'dxf' => 'CAD',
  43. // Modelos de 3D Studio
  44. '3ds' => '3D',
  45. // Dibujos de Illustrator
  46. 'ai' => 'ILLUSTRATOR',
  47. // Imágenes de Photoshop
  48. 'psd' => 'PHOTOSHOP',
  49. // Formato de documento portátil
  50. 'pdf' => 'PDF',
  51. // Hoja de cálculo en Excel
  52. 'xls' => 'EXCEL', 'xlsx' => 'EXCEL',
  53. // Presentaciones de PowerPoint
  54. 'ppt' => 'POWERPOINT', 'pptx' => 'POWERPOINT',
  55. // Documentos de texto de Word
  56. 'doc' => 'WORD', 'docx' => 'WORD',
  57. // Dibujos de Visio
  58. 'vsd' => 'VISIO', 'vsdx' => 'VISIO'
  59. ];
  60. // File size limits in MB by extension
  61. private $fileSizeLimits = [
  62. // 50MB limit
  63. 'pdf' => 50, 'doc' => 50, 'docx' => 50, 'vsd' => 50, 'vsdx' => 50,
  64. // 75MB limit
  65. 'xls' => 75, 'xlsx' => 75,
  66. // 100MB limit
  67. 'ppt' => 100, 'pptx' => 100,
  68. // 250MB limit (default for all others)
  69. 'zip' => 250, 'rar' => 250, 'tar' => 250, '7z' => 250,
  70. 'mp3' => 250, 'mpeg' => 250, 'wav' => 250, 'ogg' => 250, 'opus' => 250,
  71. 'jpeg' => 250, 'jpg' => 250, 'png' => 250, 'gif' => 250, 'bmp' => 250, 'tiff' => 250, 'svg' => 250,
  72. 'txt' => 250, 'webm' => 250, 'mpeg4' => 250, 'mp4' => 250, '3gpp' => 250, 'mov' => 250, 'avi' => 250, 'wmv' => 250, 'flv' => 250,
  73. 'dwg' => 250, 'dxf' => 250, '3ds' => 250, 'ai' => 250, 'psd' => 250
  74. ];
  75. public function __construct()
  76. {
  77. $this->responseController = new ResponseController();
  78. $this->encryptionController = new EncryptionController();
  79. $this->documentManagementController = new DocumentManagementController();
  80. }
  81. /**
  82. * Main validation endpoint that validates both Excel and ZIP files
  83. * Checks Excel headers, ZIP integrity, file listings, and compares them
  84. */
  85. public function validateFiles(Request $request)
  86. {
  87. // Validate request inputs
  88. $validator = Validator::make($request->all(), [
  89. 'id_user' => 'required|string',
  90. 'linea' => 'required|integer',
  91. 'excel_file' => 'required|file|mimes:xlsx,xls',
  92. 'zip_file' => 'required|file|mimes:zip'
  93. ]);
  94. if ($validator->fails()) {
  95. return $this->responseController->makeResponse(
  96. true,
  97. 'Se encontraron uno o más errores.',
  98. $this->responseController->makeErrors($validator->errors()->messages()),
  99. 400
  100. );
  101. }
  102. $idUser = $this->encryptionController->decrypt($request->input('id_user'));
  103. if(!$idUser){
  104. return $this->responseController->makeResponse(true, "El id del usuario que realizó la petición no fue encriptado correctamente", [], 400);
  105. }
  106. // Validate Excel file headers structure
  107. $excelValidation = $this->validateExcelHeaders($request->file('excel_file'));
  108. if ($excelValidation['error']) {
  109. return $this->responseController->makeResponse(true, $excelValidation['message'], [], 400);
  110. }
  111. // Extract and validate file listings from Excel
  112. $filesValidation = $this->extractAndValidateFiles($request->file('excel_file'));
  113. if ($filesValidation['error']) {
  114. return $this->responseController->makeResponse(true, $filesValidation['message'], [], 400);
  115. }
  116. // Validate ZIP file integrity
  117. $zipValidation = $this->validateZipFile($request->file('zip_file'));
  118. if ($zipValidation['error']) {
  119. return $this->responseController->makeResponse(true, $zipValidation['message'], [], 400);
  120. }
  121. // Compare Excel file listings with ZIP contents
  122. $comparison = $this->compareExcelWithZip($filesValidation['files'], $request->file('zip_file'));
  123. // Check for file size validation errors
  124. if (isset($comparison['error'])) {
  125. return $this->responseController->makeResponse(true, $comparison['error'], [], 400);
  126. }
  127. // Upload temp files if validation is successful
  128. if ($comparison['valid']) {
  129. $tempFiles = $this->uploadTempFiles($request);
  130. if ($tempFiles['error']) {
  131. return $this->responseController->makeResponse(true, $tempFiles['message'], [], 400);
  132. }
  133. // Extract and save individual files as temp
  134. $individualTempFiles = $this->extractAndSaveIndividualFilesAsTemp($request->file('zip_file'), $request->input('linea'), $idUser);
  135. if ($individualTempFiles === false) {
  136. return $this->responseController->makeResponse(true, 'Error procesando archivos individuales', [], 400);
  137. }
  138. $comparison['temp_files'] = $tempFiles['files'];
  139. $comparison['individual_temp_files'] = $individualTempFiles;
  140. }
  141. return $this->responseController->makeResponse(false, 'Validación completada.', $comparison);
  142. }
  143. /**
  144. * Validates that Excel file has the correct headers in row 7
  145. * Each column must match the expected category name exactly
  146. */
  147. private function validateExcelHeaders($file)
  148. {
  149. try {
  150. $spreadsheet = IOFactory::load($file->getPathname());
  151. $worksheet = $spreadsheet->getActiveSheet();
  152. // Check each expected header in row 7
  153. foreach ($this->expectedHeaders as $header) {
  154. $cellValue = $worksheet->getCell($header['letter'] . '7')->getValue();
  155. if (trim($cellValue) !== $header['category']) {
  156. return [
  157. 'error' => true,
  158. 'message' => "El encabezado en la columna {$header['letter']} no coincide. Se esperaba: '{$header['category']}', se encontró: '{$cellValue}'"
  159. ];
  160. }
  161. }
  162. return ['error' => false];
  163. } catch (\Exception $e) {
  164. return ['error' => true, 'message' => 'Error al procesar el archivo Excel: ' . $e->getMessage()];
  165. }
  166. }
  167. /**
  168. * Validates ZIP file integrity and ensures it's not empty
  169. */
  170. private function validateZipFile($file)
  171. {
  172. $zip = new ZipArchive();
  173. $result = $zip->open($file->getPathname());
  174. if ($result !== TRUE) {
  175. return ['error' => true, 'message' => 'No se pudo abrir el archivo ZIP.'];
  176. }
  177. if ($zip->numFiles === 0) {
  178. $zip->close();
  179. return ['error' => true, 'message' => 'El archivo ZIP está vacío.'];
  180. }
  181. $zip->close();
  182. return ['error' => false];
  183. }
  184. /**
  185. * Extracts file listings from Excel starting from row 8
  186. * Validates file extensions and creates structured file list
  187. * Only processes rows with equipment code (column D)
  188. */
  189. private function extractAndValidateFiles($file)
  190. {
  191. try {
  192. $spreadsheet = IOFactory::load($file->getPathname());
  193. $worksheet = $spreadsheet->getActiveSheet();
  194. $highestRow = $worksheet->getHighestRow();
  195. $files = [];
  196. // Process each row starting from row 8 (data rows)
  197. for ($row = 8; $row <= $highestRow; $row++) {
  198. $equipmentCode = trim($worksheet->getCell('D' . $row)->getValue());
  199. if (empty($equipmentCode)) continue; // Skip rows without equipment code
  200. $hasFiles = false;
  201. $rowFiles = [];
  202. // Check each file category column (excluding equipment code column D)
  203. foreach ($this->expectedHeaders as $header) {
  204. if ($header['letter'] === 'D') continue;
  205. $cellValue = trim($worksheet->getCell($header['letter'] . $row)->getValue());
  206. if (empty($cellValue)) continue;
  207. // Handle multiple files separated by commas
  208. $fileNames = explode(',', $cellValue);
  209. foreach ($fileNames as $fileName) {
  210. $fileName = trim($fileName);
  211. if (empty($fileName)) continue;
  212. // Validate file extension
  213. $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  214. if (!isset($this->extensionTypes[$extension])) {
  215. return [
  216. 'error' => true,
  217. 'message' => "Extensión inválida '{$extension}' en archivo '{$fileName}' para equipo '{$equipmentCode}'"
  218. ];
  219. }
  220. $rowFiles[] = [
  221. 'equipment_code' => $equipmentCode,
  222. 'category' => $header['category'],
  223. 'file_name' => $fileName,
  224. 'type' => $this->extensionTypes[$extension]
  225. ];
  226. $hasFiles = true;
  227. }
  228. }
  229. if ($hasFiles) {
  230. $files = array_merge($files, $rowFiles);
  231. }
  232. }
  233. return ['error' => false, 'files' => $files];
  234. } catch (\Exception $e) {
  235. return ['error' => true, 'message' => 'Error al extraer archivos del Excel: ' . $e->getMessage()];
  236. }
  237. }
  238. /**
  239. * Compares file listings from Excel with actual files in ZIP
  240. * Returns validation status and lists of missing/extra files
  241. */
  242. private function compareExcelWithZip($excelFiles, $zipFile)
  243. {
  244. $zip = new ZipArchive();
  245. $zip->open($zipFile->getPathname());
  246. // Extract all file names and sizes from ZIP
  247. $zipFiles = [];
  248. $zipFileSizes = [];
  249. for ($i = 0; $i < $zip->numFiles; $i++) {
  250. $fullPath = $zip->getNameIndex($i);
  251. // Skip directories (entries ending with /)
  252. if (substr($fullPath, -1) === '/') {
  253. continue;
  254. }
  255. // Extract filename and size
  256. $fileName = basename($fullPath);
  257. if (!empty($fileName)) {
  258. $zipFiles[] = $fileName;
  259. $zipFileSizes[$fileName] = $zip->statIndex($i)['size'];
  260. }
  261. }
  262. $zip->close();
  263. // Validate file sizes
  264. foreach ($zipFileSizes as $fileName => $size) {
  265. $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  266. if (isset($this->fileSizeLimits[$extension])) {
  267. $limitMB = $this->fileSizeLimits[$extension];
  268. $limitBytes = $limitMB * 1024 * 1024;
  269. if ($size > $limitBytes) {
  270. $sizeMB = round($size / (1024 * 1024), 2);
  271. return [
  272. 'valid' => false,
  273. 'error' => "El archivo '{$fileName}' excede el límite de tamaño. Tamaño: {$sizeMB}MB, Límite: {$limitMB}MB"
  274. ];
  275. }
  276. }
  277. }
  278. // Get file names from Excel listings
  279. $excelFileNames = array_column($excelFiles, 'file_name');
  280. // Find discrepancies between Excel and ZIP
  281. $missingInZip = array_diff($excelFileNames, $zipFiles);
  282. $extraInZip = array_diff($zipFiles, $excelFileNames);
  283. return [
  284. 'valid' => empty($missingInZip) && empty($extraInZip),
  285. 'missing_in_zip' => array_values($missingInZip),
  286. 'extra_in_zip' => array_values($extraInZip)
  287. ];
  288. }
  289. /**
  290. * Uploads Excel and ZIP files as temporary files using DocumentManagementController
  291. */
  292. private function uploadTempFiles(Request $request)
  293. {
  294. try {
  295. $tempFiles = [];
  296. // Upload Excel file
  297. $excelRequest = new Request();
  298. $excelRequest->files->set('file', $request->file('excel_file'));
  299. $excelRequest->merge([
  300. 'id_user' => $request->input('id_user'),
  301. 'linea' => $request->input('linea')
  302. ]);
  303. $excelResponse = $this->documentManagementController->uploadTempFile($excelRequest);
  304. $excelData = json_decode($excelResponse->getContent());
  305. if ($excelData->error) {
  306. $errorMsg = isset($excelData->message) ? $excelData->message : 'Error desconocido subiendo Excel';
  307. return ['error' => true, 'message' => 'Error subiendo Excel: ' . $errorMsg];
  308. }
  309. $tempFiles['excel'] = $excelData->response->idArchivo;
  310. // Upload ZIP file
  311. $zipRequest = new Request();
  312. $zipRequest->files->set('file', $request->file('zip_file'));
  313. $zipRequest->merge([
  314. 'id_user' => $request->input('id_user'),
  315. 'linea' => $request->input('linea')
  316. ]);
  317. $zipResponse = $this->documentManagementController->uploadTempFile($zipRequest);
  318. $zipData = json_decode($zipResponse->getContent());
  319. if ($zipData->error) {
  320. $errorMsg = isset($zipData->message) ? $zipData->message : 'Error desconocido subiendo ZIP';
  321. return ['error' => true, 'message' => 'Error subiendo ZIP: ' . $errorMsg];
  322. }
  323. $tempFiles['zip'] = $zipData->response->idArchivo;
  324. return ['error' => false, 'files' => $tempFiles];
  325. } catch (\Exception $e) {
  326. return ['error' => true, 'message' => 'Error en uploadTempFiles: ' . $e->getMessage()];
  327. }
  328. }
  329. /**
  330. * Process endpoint that moves temp files to final storage
  331. */
  332. public function processLoadArchives(Request $request)
  333. {
  334. $validator = Validator::make($request->all(), [
  335. 'id_user' => 'required|string',
  336. 'linea' => 'required|integer',
  337. 'temp_files' => 'required|array',
  338. 'temp_files.excel' => 'required|string',
  339. 'temp_files.zip' => 'required|string',
  340. 'individual_temp_files' => 'required|array'
  341. ]);
  342. if ($validator->fails()) {
  343. return $this->responseController->makeResponse(
  344. true,
  345. 'Se encontraron uno o más errores.',
  346. $this->responseController->makeErrors($validator->errors()->messages()),
  347. 400
  348. );
  349. }
  350. $form = $request->all();
  351. $idUser = $this->encryptionController->decrypt($form['id_user']);
  352. if (!$idUser) {
  353. return $this->responseController->makeResponse(true, 'ID de usuario inválido.', [], 400);
  354. }
  355. $finalFiles = [];
  356. try {
  357. // Move Excel to final
  358. $excelFinal = $this->moveToFinal($form['temp_files']['excel'], $form['linea'], $idUser);
  359. if (!$excelFinal) {
  360. return $this->responseController->makeResponse(true, 'Error procesando Excel', [], 400);
  361. }
  362. $finalFiles['excel'] = $excelFinal;
  363. // Move ZIP to final
  364. $zipFinal = $this->moveToFinal($form['temp_files']['zip'], $form['linea'], $idUser);
  365. if (!$zipFinal) {
  366. return $this->responseController->makeResponse(true, 'Error procesando ZIP', [], 400);
  367. }
  368. $finalFiles['zip'] = $zipFinal;
  369. // Move individual temp files to final storage
  370. $individualFiles = [];
  371. foreach ($form['individual_temp_files'] as $tempFile) {
  372. $finalFileId = $this->moveToFinal($tempFile['temp_id'], $form['linea'], $idUser);
  373. if ($finalFileId) {
  374. $individualFiles[] = [
  375. 'original_name' => $tempFile['original_name'],
  376. 'final_id' => $finalFileId
  377. ];
  378. }
  379. }
  380. $finalFiles['individual_files'] = $individualFiles;
  381. return $this->responseController->makeResponse(false, 'Archivos procesados exitosamente.', $finalFiles);
  382. } catch (\Exception $e) {
  383. return $this->responseController->makeResponse(true, 'Error interno: ' . $e->getMessage(), [], 500);
  384. }
  385. }
  386. /**
  387. * Moves a temporary file to final storage using DocumentManagementController
  388. */
  389. private function moveToFinal($tempId, $line, $idUser)
  390. {
  391. try {
  392. $tempIdDec = $this->encryptionController->decrypt($tempId);
  393. if (!$tempIdDec) {
  394. return false;
  395. }
  396. $tempFile = DB::table('S002V01TARTE')->where('ARTE_IDAR', $tempIdDec)->first();
  397. if (!$tempFile) {
  398. return false;
  399. }
  400. $result = $this->documentManagementController->moveFinalFile($line, 'GDEL', 'CA', $tempFile, $idUser);
  401. return $result[0] ? $result[1] : false;
  402. } catch (\Exception $e) {
  403. return false;
  404. }
  405. }
  406. /**
  407. * Extracts individual files from ZIP and saves them as temporary files
  408. */
  409. private function extractAndSaveIndividualFilesAsTemp($zipFile, $line, $idUser)
  410. {
  411. try {
  412. $zip = new ZipArchive();
  413. if ($zip->open($zipFile->getPathname()) !== TRUE) {
  414. return false;
  415. }
  416. $tempFiles = [];
  417. $tempDir = storage_path('app/tempFiles/extracted_' . time());
  418. mkdir($tempDir, 0755, true);
  419. for ($i = 0; $i < $zip->numFiles; $i++) {
  420. $fullPath = $zip->getNameIndex($i);
  421. // Skip directories
  422. if (substr($fullPath, -1) === '/') {
  423. continue;
  424. }
  425. $fileName = basename($fullPath);
  426. if (empty($fileName)) continue;
  427. // Extract file to temp directory
  428. if ($zip->extractTo($tempDir, $fullPath)) {
  429. $finalExtractPath = $tempDir . '/' . $fileName;
  430. if (file_exists($tempDir . '/' . $fullPath)) {
  431. rename($tempDir . '/' . $fullPath, $finalExtractPath);
  432. }
  433. if (file_exists($finalExtractPath)) {
  434. // Upload as temp file
  435. $tempFileId = $this->uploadExtractedFileAsTemp($finalExtractPath, $fileName, $line, $idUser);
  436. if ($tempFileId) {
  437. $tempFiles[] = [
  438. 'original_name' => $fileName,
  439. 'temp_id' => $tempFileId
  440. ];
  441. }
  442. unlink($finalExtractPath);
  443. }
  444. }
  445. }
  446. $zip->close();
  447. $this->removeDirectory($tempDir);
  448. return $tempFiles;
  449. } catch (\Exception $e) {
  450. return false;
  451. }
  452. }
  453. /**
  454. * Uploads an extracted file as temporary file
  455. */
  456. private function uploadExtractedFileAsTemp($filePath, $fileName, $line, $idUser)
  457. {
  458. try {
  459. $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  460. $mimeType = $this->getMimeType($extension);
  461. // Create a temporary uploaded file object
  462. $tempFile = new \Illuminate\Http\UploadedFile(
  463. $filePath,
  464. $fileName,
  465. $mimeType,
  466. null,
  467. true
  468. );
  469. $request = new Request();
  470. $request->files->set('file', $tempFile);
  471. $request->merge([
  472. 'id_user' => $this->encryptionController->encrypt($idUser),
  473. 'linea' => $line
  474. ]);
  475. $response = $this->documentManagementController->uploadTempFile($request);
  476. $data = json_decode($response->getContent());
  477. return $data->error ? false : $data->response->idArchivo;
  478. } catch (\Exception $e) {
  479. return false;
  480. }
  481. }
  482. /**
  483. * Gets MIME type for file extension
  484. */
  485. private function getMimeType($extension)
  486. {
  487. $mimeTypes = [
  488. 'pdf' => 'application/pdf',
  489. 'doc' => 'application/msword',
  490. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  491. 'xls' => 'application/vnd.ms-excel',
  492. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  493. 'ppt' => 'application/vnd.ms-powerpoint',
  494. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  495. 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg',
  496. 'png' => 'image/png', 'gif' => 'image/gif', 'bmp' => 'image/bmp',
  497. 'txt' => 'text/plain', 'dwg' => 'application/acad', 'dxf' => 'application/dxf'
  498. ];
  499. return $mimeTypes[$extension] ?? 'application/octet-stream';
  500. }
  501. /**
  502. * Recursively removes a directory and its contents
  503. */
  504. private function removeDirectory($dir)
  505. {
  506. if (!is_dir($dir)) return;
  507. $files = array_diff(scandir($dir), ['.', '..']);
  508. foreach ($files as $file) {
  509. $path = $dir . '/' . $file;
  510. is_dir($path) ? $this->removeDirectory($path) : unlink($path);
  511. }
  512. rmdir($dir);
  513. }
  514. }