12345678910111213141516171819202122232425262728293031323334 |
- <?php
- class LogUploadAction implements IAction {
- public function execute() {
- $projectId = $_POST['project_id'] ?? $_GET['project_id'];
- $userId = $_SESSION['user_id'];
- $fileList = json_decode($_POST['filelist'] ?? $_GET['filelist']);
- $uploadtime = $_POST['uploadtime'] ?? $_GET['uploadtime'];
- $database = SqliteDatabase::getSingleton();
- $sql = "DELETE FROM upload_logs WHERE user_id = :user_id AND project_id = :project_id AND uploadtime != datetime(:uploadtime);";
- $preparedQuery = $database->prepare($sql);
- $preparedQuery->bindValue(':user_id', $userId);
- $preparedQuery->bindValue(':project_id', $projectId);
- $preparedQuery->bindValue(':uploadtime', $uploadtime);
- $result = $preparedQuery->execute();
- $database->query($sql);
- $sql = "INSERT INTO upload_logs (project_id, user_id, filepath, uploadtime) VALUES ";
- $insertRows = array();
- foreach($fileList as $filepath) {
- $insertRows[] = "(" . $projectId . ", " . $userId . ", '" . $filepath . "', datetime('" . $uploadtime . "'))";
- }
- $sql .= implode(", ", $insertRows);
-
- $database->query($sql);
- $data = array("message" => "upload log written with " . count($fileList) . " files");
- return $data;
- }
- }
|