LogUploadAction.class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class LogUploadAction implements IAction {
  3. public function execute() {
  4. $projectId = $_POST['project_id'] ?? $_GET['project_id'];
  5. $userId = $_SESSION['user_id'];
  6. $fileList = json_decode($_POST['filelist'] ?? $_GET['filelist']);
  7. $uploadtime = $_POST['uploadtime'] ?? $_GET['uploadtime'];
  8. $database = SqliteDatabase::getSingleton();
  9. $sql = "DELETE FROM upload_logs WHERE user_id = :user_id AND project_id = :project_id AND uploadtime != datetime(:uploadtime);";
  10. $preparedQuery = $database->prepare($sql);
  11. $preparedQuery->bindValue(':user_id', $userId);
  12. $preparedQuery->bindValue(':project_id', $projectId);
  13. $preparedQuery->bindValue(':uploadtime', $uploadtime);
  14. $result = $preparedQuery->execute();
  15. $database->query($sql);
  16. $sql = "INSERT INTO upload_logs (project_id, user_id, filepath, uploadtime) VALUES ";
  17. $insertRows = array();
  18. foreach($fileList as $filepath) {
  19. $insertRows[] = "(" . $projectId . ", " . $userId . ", '" . $filepath . "', datetime('" . $uploadtime . "'))";
  20. }
  21. $sql .= implode(", ", $insertRows);
  22. $database->query($sql);
  23. $data = array("message" => "upload log written with " . count($fileList) . " files");
  24. return $data;
  25. }
  26. }