|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Russell Michell 2018 <[email protected]> |
|
4
|
|
|
* @package silverstripe-verifiable |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PhpTek\Verifiable\Cron; |
|
8
|
|
|
|
|
9
|
|
|
use SilverStripe\CronTask\Interfaces\CronTask; |
|
10
|
|
|
use PhpTek\Verifiable\ORM\FieldType\ChainpointProof; |
|
11
|
|
|
use SilverStripe\ORM\DataObject; |
|
12
|
|
|
use SilverStripe\Core\Extensible; |
|
13
|
|
|
use PhpTek\Verifiable\Verify\VerifiableExtension; |
|
14
|
|
|
use SilverStripe\ORM\DataList; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Assumes of course that the CronTask cron is running on the server. See README. |
|
18
|
|
|
*/ |
|
19
|
|
|
//class ChainpointFullProofTask implements CronTask |
|
20
|
|
|
//{ |
|
21
|
|
|
// use Extensible; |
|
22
|
|
|
// |
|
23
|
|
|
// /** |
|
24
|
|
|
// * {@inheritdoc} |
|
25
|
|
|
// */ |
|
26
|
|
|
// public function getSchedule() |
|
27
|
|
|
// { |
|
28
|
|
|
// return '0 1 * * *'; // 01:00 every day |
|
29
|
|
|
// } |
|
30
|
|
|
// |
|
31
|
|
|
// /** |
|
32
|
|
|
// * {@inheritdoc} |
|
33
|
|
|
// * @throws Exception |
|
34
|
|
|
// */ |
|
35
|
|
|
// public function process() |
|
36
|
|
|
// { |
|
37
|
|
|
// if (!$backend = $this->verifiableService->getBackend() === 'chainpoint') { |
|
38
|
|
|
// throw new Exception(sprintf('Cannot use %s backend with %s!', $backend, __CLASS__)); |
|
39
|
|
|
// } |
|
40
|
|
|
// |
|
41
|
|
|
// $fullProofs = $this->verifiableService->read($this->getPartials()); |
|
42
|
|
|
// $this->writeFull($fullProofs); |
|
43
|
|
|
// } |
|
44
|
|
|
// |
|
45
|
|
|
// /** |
|
46
|
|
|
// * Fetch all partial proofs, ready to make them whole again. The returned |
|
47
|
|
|
// * |
|
48
|
|
|
// * @return array |
|
49
|
|
|
// */ |
|
50
|
|
|
// protected function getPartials() |
|
51
|
|
|
// { |
|
52
|
|
|
// // Get decorated classes |
|
53
|
|
|
// $verifiableClasses = array_filter(self::get_extensions(DataObject::class), function($v) { |
|
54
|
|
|
// return $v === VerifiableExtension::class; |
|
55
|
|
|
// }); |
|
56
|
|
|
// |
|
57
|
|
|
// // Now fetch the relevant records, filtering on incomplete proofs |
|
58
|
|
|
// DataList::create($args); |
|
59
|
|
|
// } |
|
60
|
|
|
// |
|
61
|
|
|
// /** |
|
62
|
|
|
// * Takes a large JSON string, converts it to a ChainpointProof object and |
|
63
|
|
|
// * updates the necessary records. |
|
64
|
|
|
// * |
|
65
|
|
|
// * @param string $fullProofs |
|
66
|
|
|
// * @return void |
|
67
|
|
|
// */ |
|
68
|
|
|
// protected function writeFull($proofs) |
|
69
|
|
|
// { |
|
70
|
|
|
// $jsonObject = ChainpointProof::create()->setValue($proofs); |
|
71
|
|
|
// } |
|
72
|
|
|
// |
|
73
|
|
|
//} |
|
74
|
|
|
|