Browse Source

Composer updates, added CallbackPresenter (taken over)

Composer: added ublaboo/mailing, updated existing dependecies
kudlav 1 year ago
parent
commit
9f61d867d8
5 changed files with 243 additions and 29 deletions
  1. 4 0
      app/config/config.neon
  2. 141 0
      app/presenters/CallbackPresenter.php
  3. 2 1
      composer.json
  4. 95 27
      composer.lock
  5. 1 1
      vendor/autoload.php

+ 4 - 0
app/config/config.neon

@@ -23,3 +23,7 @@ services:
 	- App\Model\Parameters(@container::getParameters())
 	- App\Model\VideoManager
 	- App\Model\TokenManager
+
+
+extensions:
+	mailing: Ublaboo\Mailing\DI\MailingExtension

+ 141 - 0
app/presenters/CallbackPresenter.php

@@ -0,0 +1,141 @@
+<?php
+
+namespace App\Presenters;
+
+use Nette;
+use App\Model\Repository\ProcessingRepository;
+use App\Model\Repository\RecordingRepository;
+use App\Model\Entity\Processing;
+use App\Model\Entity\Recording;
+use DateTime;
+use Tracy\Debugger;
+use Ublaboo\Mailing\MailFactory;
+use App\Utilities;
+use Nette\Http\Request;
+use App\Model\SgeInfo;
+
+
+class CallbackPresenter extends Nette\Application\UI\Presenter
+{
+	/** @var ProcessingRepository @inject */
+	public $processingRepository;
+
+	/** @var RecordingRepository @inject */
+	public $recordingRepository;
+
+	/** @var MailFactory @inject */
+	public $mailFactory;
+
+	/** @var SgeInfo @inject */
+	public $sgeInfo;
+
+
+	public function actionDefault()
+	{
+		$httpRequest = $this->getHttpRequest();
+
+		switch ($httpRequest->getMethod()) {
+			case 'POST':
+				$this->processPost($httpRequest);
+				break;
+			case 'GET':
+				$this->processGet($httpRequest);
+				break;
+		}
+
+	}
+
+	public function processGet(Request $httpRequest)
+	{
+		$jobId = $httpRequest->getQuery('job_id') ?: '';
+		$status = $httpRequest->getQuery('status') ?: '';
+		$message = $httpRequest->getQuery('message') ?: '';
+		$process = $httpRequest->getQuery('process') ?: '';
+		$block = $httpRequest->getQuery('block') ?: '';
+		$hostIp = $httpRequest->getQuery('hostip') ?: '';
+		$hostName = $httpRequest->getQuery('hostname') ?: '';
+		$sgeJobId = intval($httpRequest->getQuery('sge_job_id'));
+		$sign = $httpRequest->getQuery('sign') ?: '';
+
+
+		if ($this->context->parameters['signVerification']) {
+			$query = $_SERVER['QUERY_STRING'];
+			$strToSign = trim(substr($query, 0, strpos($query, 'sign=')-1));
+			if (!$this->verifySignature($strToSign, $sign)) {
+				$this->setView('error-signature');
+				return;
+			}
+		}
+
+		$recording = $this->recordingRepository->getByJobId($jobId);
+		if ($recording) {
+			$entity = new Processing([
+			    'recording' => $recording,
+			    'datetime' => new DateTime,
+			    'block' => $block,
+			    'status' => $status,
+			    'process' => $process,
+			    'message' => $message,
+			    'hostIp' => $hostIp,
+			    'hostName' => $hostName,
+			    'sgeJobId' => $sgeJobId
+			]);
+
+			$this->processingRepository->insert($entity);
+			$diffArray = $this->recordingRepository->updateByProcessing($recording, FALSE);
+
+			if (isset($diffArray['status']) && in_array($recording->getStatus(), [Recording::STATUS_DONE, Recording::STATUS_ERROR])) {
+
+				// invoke callback url
+				Utilities::callUrl($recording->getCallbackUrl(TRUE));
+
+				if ($recording->getStatus() == Recording::STATUS_DONE) {
+					$mailClass = 'App\Model\Mail\ProcessingDoneMail';
+				} elseif ($recording->getStatus() == Recording::STATUS_ERROR) {
+					$mailClass = 'App\Model\Mail\ProcessingErrorMail';
+				}
+
+				if (isset($mailClass)) {
+					$params = ['recording' => $recording];
+					$mail = $this->mailFactory->createByType($mailClass, $params);
+					$mail->send();
+				}
+			}
+
+			$this->setView('success');
+		} else {
+			$this->setView('error');
+		}
+	}
+
+	public function processPost(Request $httpRequest)
+	{
+		$sign = $httpRequest->getQuery('sign') ?: '';
+
+		// potreba upravit
+		if ($this->context->parameters['signVerification']) {
+			$strToSign = $httpRequest->getRawBody();
+			if (!$this->verifySignature($strToSign, $sign)) {
+				$this->setView('error-signature');
+				return;
+			}
+		}
+
+		if (strlen($sign) > 0) {
+			$this->sgeInfo->write($httpRequest->getRawBody());
+			$this->setView('success');
+		} else {
+			$this->setView('error');
+		}
+	}
+
+	private function verifySignature($strToSign, $signature)
+	{
+		if ($signature !== sha1($strToSign . $this->context->parameters['salt'])) {
+			Debugger::log('Signature error ' . $signature . ' :: ' .$strToSign);
+			return FALSE;
+		}
+		return TRUE;
+	}
+
+}

+ 2 - 1
composer.json

@@ -19,7 +19,8 @@
 		"nette/security": "^2.4",
 		"nette/utils": "^2.4",
 		"latte/latte": "^2.4",
-		"tracy/tracy": "^2.4"
+		"tracy/tracy": "^2.4",
+		"ublaboo/mailing": "^1.1"
 	},
 	"require-dev": {
 		"nette/tester": "^2.0"

+ 95 - 27
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "f0a28e5e37481070d260fb13cecf344b",
+    "content-hash": "293d9342273fd9bce0d579f4d7036cfb",
     "packages": [
         {
             "name": "latte/latte",
@@ -243,16 +243,16 @@
         },
         {
             "name": "nette/caching",
-            "version": "v2.5.5",
+            "version": "v2.5.6",
             "source": {
                 "type": "git",
                 "url": "https://github.com/nette/caching.git",
-                "reference": "997d3b9868840da8b51f27565bfe1a8210e94620"
+                "reference": "1231735b5135ca02bd381b70482c052d2a90bdc9"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nette/caching/zipball/997d3b9868840da8b51f27565bfe1a8210e94620",
-                "reference": "997d3b9868840da8b51f27565bfe1a8210e94620",
+                "url": "https://api.github.com/repos/nette/caching/zipball/1231735b5135ca02bd381b70482c052d2a90bdc9",
+                "reference": "1231735b5135ca02bd381b70482c052d2a90bdc9",
                 "shasum": ""
             },
             "require": {
@@ -308,7 +308,7 @@
                 "nette",
                 "sqlite"
             ],
-            "time": "2017-08-18T15:20:18+00:00"
+            "time": "2017-08-30T12:12:25+00:00"
         },
         {
             "name": "nette/component-model",
@@ -441,16 +441,16 @@
         },
         {
             "name": "nette/di",
-            "version": "v2.4.9",
+            "version": "v2.4.10",
             "source": {
                 "type": "git",
                 "url": "https://github.com/nette/di.git",
-                "reference": "25437788ff126d0ae6b1f2f684ecdd823812abba"
+                "reference": "a4b3be935b755f23aebea1ce33d7e3c832cdff98"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nette/di/zipball/25437788ff126d0ae6b1f2f684ecdd823812abba",
-                "reference": "25437788ff126d0ae6b1f2f684ecdd823812abba",
+                "url": "https://api.github.com/repos/nette/di/zipball/a4b3be935b755f23aebea1ce33d7e3c832cdff98",
+                "reference": "a4b3be935b755f23aebea1ce33d7e3c832cdff98",
                 "shasum": ""
             },
             "require": {
@@ -495,9 +495,18 @@
                     "homepage": "https://nette.org/contributors"
                 }
             ],
-            "description": "Nette Dependency Injection Component",
+            "description": "💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
             "homepage": "https://nette.org",
-            "time": "2017-07-11T17:55:11+00:00"
+            "keywords": [
+                "compiled",
+                "di",
+                "dic",
+                "factory",
+                "ioc",
+                "nette",
+                "static"
+            ],
+            "time": "2017-08-31T22:42:00+00:00"
         },
         {
             "name": "nette/finder",
@@ -812,21 +821,21 @@
         },
         {
             "name": "nette/php-generator",
-            "version": "v2.6.3",
+            "version": "v3.0.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/nette/php-generator.git",
-                "reference": "78c898808d3a1018cc81f9d7108bc645129776c8"
+                "reference": "eb2dbc9c3409e9db40568109ca4994d51373b60c"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nette/php-generator/zipball/78c898808d3a1018cc81f9d7108bc645129776c8",
-                "reference": "78c898808d3a1018cc81f9d7108bc645129776c8",
+                "url": "https://api.github.com/repos/nette/php-generator/zipball/eb2dbc9c3409e9db40568109ca4994d51373b60c",
+                "reference": "eb2dbc9c3409e9db40568109ca4994d51373b60c",
                 "shasum": ""
             },
             "require": {
                 "nette/utils": "^2.4.2 || ~3.0.0",
-                "php": ">=5.6.0"
+                "php": ">=7.0"
             },
             "conflict": {
                 "nette/nette": "<2.2"
@@ -838,7 +847,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "2.6-dev"
+                    "dev-master": "3.0-dev"
                 }
             },
             "autoload": {
@@ -862,9 +871,15 @@
                     "homepage": "https://nette.org/contributors"
                 }
             ],
-            "description": "Nette PHP Generator",
+            "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.1 features.",
             "homepage": "https://nette.org",
-            "time": "2017-07-14T07:06:27+00:00"
+            "keywords": [
+                "code",
+                "nette",
+                "php",
+                "scaffolding"
+            ],
+            "time": "2017-07-11T19:07:13+00:00"
         },
         {
             "name": "nette/reflection",
@@ -1134,16 +1149,16 @@
         },
         {
             "name": "tracy/tracy",
-            "version": "v2.4.9",
+            "version": "v2.4.10",
             "source": {
                 "type": "git",
                 "url": "https://github.com/nette/tracy.git",
-                "reference": "efe45da0aa3a50ce5356be39f2168d7925d94f3d"
+                "reference": "5b302790edd71924dfe4ec44f499ef61df3f53a2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nette/tracy/zipball/efe45da0aa3a50ce5356be39f2168d7925d94f3d",
-                "reference": "efe45da0aa3a50ce5356be39f2168d7925d94f3d",
+                "url": "https://api.github.com/repos/nette/tracy/zipball/5b302790edd71924dfe4ec44f499ef61df3f53a2",
+                "reference": "5b302790edd71924dfe4ec44f499ef61df3f53a2",
                 "shasum": ""
             },
             "require": {
@@ -1197,7 +1212,60 @@
                 "nette",
                 "profiler"
             ],
-            "time": "2017-08-16T17:13:36+00:00"
+            "time": "2017-10-04T18:43:42+00:00"
+        },
+        {
+            "name": "ublaboo/mailing",
+            "version": "v1.1.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/ublaboo/mailing.git",
+                "reference": "8fc5a8fda928886b17514f34dab15540faae65bc"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/ublaboo/mailing/zipball/8fc5a8fda928886b17514f34dab15540faae65bc",
+                "reference": "8fc5a8fda928886b17514f34dab15540faae65bc",
+                "shasum": ""
+            },
+            "require": {
+                "latte/latte": "~2.3|~2.4",
+                "nette/application": "~2.3|~2.4",
+                "nette/di": "~2.3|~2.4",
+                "nette/mail": "~2.3|~2.4",
+                "nette/utils": "~2.3|~2.4"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9",
+                "nette/tester": "~1.6.1",
+                "tracy/tracy": "^2.3|^2.4"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Ublaboo\\Mailing\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Pavel Janda",
+                    "homepage": "http://paveljanda.com"
+                }
+            ],
+            "description": "Extension for Nette Framework: Easy & object-oriented way of sending & logging mails",
+            "homepage": "http://ublaboo.paveljanda.com/mailing",
+            "keywords": [
+                "extension",
+                "log",
+                "mail",
+                "mailing",
+                "nette"
+            ],
+            "time": "2016-08-14T08:19:14+00:00"
         }
     ],
     "packages-dev": [
@@ -1270,10 +1338,10 @@
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
-        "php": ">= 5.6"
+        "php": ">= 7.0"
     },
     "platform-dev": [],
     "platform-overrides": {
-        "php": "5.6"
+        "php": "7.0"
     }
 }

+ 1 - 1
vendor/autoload.php

@@ -2,6 +2,6 @@
 
 // autoload.php @generated by Composer
 
-require_once __DIR__ . '/composer' . '/autoload_real.php';
+require_once __DIR__ . '/composer/autoload_real.php';
 
 return ComposerAutoloaderInit091ed5d24b4127ffc48411e34be2086f::getLoader();