1<?php 2 3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */ 4 5use ILIAS\Setup\CallableObjective; 6use ILIAS\Setup\Objective; 7use ILIAS\Setup\Environment; 8 9/** 10 * This encapsulate one database update step which is a method on some 11 * ilDatabaseUpdateSteps-object. 12 * 13 * This is a close collaborator of ilDatabaseUpdateSteps and should most probably 14 * not be used standalone. 15 */ 16class ilDatabaseUpdateStep extends CallableObjective 17{ 18 /** 19 * @var string 20 */ 21 protected $class_name; 22 23 /** 24 * @var string 25 */ 26 protected $method_name; 27 28 public function __construct( 29 ilDatabaseUpdateSteps $parent, 30 int $num, 31 Objective ...$preconditions 32 ) { 33 $this->class_name = get_class($parent); 34 $this->method_name = \ilDatabaseUpdateSteps::STEP_METHOD_PREFIX . $num; 35 parent::__construct( 36 function (Environment $env) use ($parent, $num) { 37 $db = $env->getResource(Environment::RESOURCE_DATABASE); 38 $log = $env->getResource(\ilDatabaseUpdateStepExecutionLog::class); 39 if ($log) { 40 $log->started($this->class_name, $num); 41 } 42 call_user_func([$parent, $this->method_name], $db); 43 if ($log) { 44 $log->finished($this->class_name, $num); 45 } 46 }, 47 "Database update step {$this->class_name}::{$this->method_name}", 48 false, 49 ...$preconditions 50 ); 51 } 52 53 54 /** 55 * @inheritdocs 56 */ 57 public function getHash() : string 58 { 59 return hash( 60 "sha256", 61 $this->class_name . "::" . $this->method_name 62 ); 63 } 64} 65