Mongoer.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Meramo\mrm_be;
  3. //require '/var/phpmongodb/vendor/autoload.php';
  4. // TODO: scheduler task alle 15 min welcher
  5. // select x.deleted, x.disabled, x.source_path as source, x.target, x.target_statuscode as statusCode from sys_redirect as x where x.deleted = 0 and x.disabled = 0 order by x.updatedon DESC
  6. // abfrägt und aber ohne deleted, disabled und mit timestamp nicht älter als 16 min ;)
  7. // in key value array spielt und immer nur das aktuellste sourcepath-teil (updatedon) behält
  8. // danach durchrequesten (deleted und disabled abfrage nicht vergessen ;) )
  9. // target T3LINK überprüfen
  10. // ganz zum schluss ein delete mongo query über deleted = 1 || disabled = 1 und dann passts
  11. class Mongoer
  12. {
  13. function __construct(){}
  14. public static function sendRequest($dataType, $action, $data){
  15. // $client = new \MongoDB\Client("mongodb://db:db@mongo:27017/");
  16. $client = new \MongoDB\Client($_ENV['FE_DATABASE_DSN']);
  17. $collection = null;
  18. if($dataType == "pages")
  19. $collection = $client->abi_local->pages;
  20. if($dataType == "search")
  21. $collection = $client->abi_local->searches;
  22. if($dataType == "topthemen")
  23. $collection = $client->abi_local->topthemens;
  24. if($dataType == "themaderwoche")
  25. $collection = $client->abi_local->themaderwoches;
  26. if($dataType == "security")
  27. $collection = $client->abi_local->pagesecurities;
  28. if($dataType == "abialtcache")
  29. $collection = $client->abi_local->abialtcaches;
  30. if($dataType == "menues")
  31. $collection = $client->abi_local->menues;
  32. if($dataType == "maintenance")
  33. $collection = $client->abi_local->maintenance;
  34. if($dataType == "redirects")
  35. $collection = $client->abi_local->redirects;
  36. if($dataType == "forwardings")
  37. $collection = $client->abi_local->forwardings;
  38. if($dataType == "pdfgenjobs")
  39. $collection = $client->abi_local->pdfgenjobs;
  40. if($dataType == "chatbot")
  41. $collection = $client->abi_local->chatbot;
  42. if(!$collection) return self::log("no collection for senddata: ".$dataType);
  43. self::log("sendRequest ".$action." ".$dataType);
  44. if($action == "save"){
  45. $updateResult = $collection->updateOne(
  46. ['pageuid' => $data['pageuid']],
  47. ['$set' => $data],
  48. ['upsert' => true],
  49. );
  50. }
  51. if($action == "delete"){
  52. $collection->deleteOne(['pageuid' => $data['pageuid']]);
  53. }
  54. if($action == "deleteAll") {
  55. $collection->deleteMany([]);
  56. }
  57. }
  58. /* PRIVATES */
  59. private static function log($msg, $isString = true){
  60. if(!$isString){
  61. $msg = json_encode($msg, JSON_PRETTY_PRINT);
  62. }
  63. file_put_contents('/var/www/html/tuepotest/public/typo3temp/debug.log', $msg.PHP_EOL, FILE_APPEND);
  64. }
  65. /* Private function to drop a collection */
  66. public static function deleteAll($collection) {
  67. return $collection->deleteMany();
  68. }
  69. }