From 04eab9533a43efb013abdfe8170f7368c8e84812 Mon Sep 17 00:00:00 2001 From: mar1naj Date: Thu, 7 Feb 2013 15:45:33 -0500 Subject: [PATCH 1/3] Update Services/FileManager.php For Windows, rsync is replaced with robocopy to mirror the temp directory into the permanent one. And used Windows commands to delete directories and files. --- Services/FileManager.php | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Services/FileManager.php b/Services/FileManager.php index 4dcde21..0c22519 100644 --- a/Services/FileManager.php +++ b/Services/FileManager.php @@ -59,7 +59,16 @@ public function removeFiles($options = array()) { throw \Exception("folder option looks empty, bailing out"); } - system("rm -rf " . escapeshellarg($folder)); + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') + { + //Running on Windows + system('rd /s/q ' . escapeshellarg($folder)); + } + else + { + //Not running on Windows. Hoping it's a Linux + system("rm -rf " . escapeshellarg($folder)); + } } /** @@ -106,14 +115,34 @@ public function syncFiles($options = array()) { throw new \Exception("to_folder does not exist"); } - system("rsync -a --delete " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); - if ($result !== 0) + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') + { + //Running on Windows + system("robocopy /Mir /NP /NDL /NFL /NJH /NJS " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); + + } + else { + //Not running on Windows. Hoping it's a Linux + system("rsync -a --delete " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); + } + + if ($result !== 1) + { throw new \Exception("Sync failed"); } if (isset($options['remove_from_folder']) && $options['remove_from_folder']) { - system("rm -rf " . escapeshellarg($from)); + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') + { + //Running on Windows + system('rd /s/q ' . escapeshellarg($from)); + } + else + { + //Not running on Windows. Hoping it's a Linux + system("rm -rf " . escapeshellarg($from)); + } } } else From 340384ab3b35508280cc5693960c792afd346f27 Mon Sep 17 00:00:00 2001 From: mar1naj Date: Thu, 7 Feb 2013 16:17:30 -0500 Subject: [PATCH 2/3] Update Services/FileManager.php --- Services/FileManager.php | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Services/FileManager.php b/Services/FileManager.php index 0c22519..b878990 100644 --- a/Services/FileManager.php +++ b/Services/FileManager.php @@ -61,14 +61,14 @@ public function removeFiles($options = array()) } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - //Running on Windows - system('rd /s/q ' . escapeshellarg($folder)); - } + //Running on Windows + system('rd /s/q ' . escapeshellarg($folder)); + } else { - //Not running on Windows. Hoping it's a Linux - system("rm -rf " . escapeshellarg($folder)); - } + //Not running on Windows. Hoping it's a Linux + system("rm -rf " . escapeshellarg($folder)); + } } /** @@ -115,19 +115,19 @@ public function syncFiles($options = array()) { throw new \Exception("to_folder does not exist"); } - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - //Running on Windows - system("robocopy /Mir /NP /NDL /NFL /NJH /NJS " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); - - } + //Running on Windows + system("robocopy /Mir /NP /NDL /NFL /NJH /NJS " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); + $kk=1; + } else { - //Not running on Windows. Hoping it's a Linux - system("rsync -a --delete " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); - } - - if ($result !== 1) + //Not running on Windows. Hoping it's a Linux + system("rsync -a --delete " . escapeshellarg($from . '/') . " " . escapeshellarg($to), $result); + $kk=0; + } + if ($result !== $kk) { throw new \Exception("Sync failed"); } @@ -135,14 +135,14 @@ public function syncFiles($options = array()) { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - //Running on Windows - system('rd /s/q ' . escapeshellarg($from)); - } + //Running on Windows + system('rd /s/q ' . escapeshellarg($from)); + } else { - //Not running on Windows. Hoping it's a Linux - system("rm -rf " . escapeshellarg($from)); - } + //Not running on Windows. Hoping it's a Linux + system("rm -rf " . escapeshellarg($from)); + } } } else From 7dec05da30e72c178de68bd02bb08e3cadd925a9 Mon Sep 17 00:00:00 2001 From: mar1naj Date: Fri, 1 Mar 2013 11:55:34 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53204a3..83df703 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Let's assume there is an edit.html.twig template associated with the edit action $(function() { new PunkAveFileUploader({ 'uploadUrl': {{ path('upload', { editId: editId }) | json_encode | raw }}, - 'viewUrl': {{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }}, + 'viewUrl': {{ '/uploads/tmp/attachments/#{editId}' | json_encode | raw }}, 'el': '.file-uploader', 'existingFiles': {{ existingFiles | json_encode | raw }}, 'delaySubmitWhileUploading': '.edit-form'