mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
- Added new core controller CLI_Controller
- Adapted all the controllers jobs to use this new controller
This commit is contained in:
@@ -11,12 +11,13 @@
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class AmpelMail extends FHC_Controller
|
||||
class AmpelMail extends CLI_Controller
|
||||
{
|
||||
private $CIS_AMPELVERWALTUNG_URL;
|
||||
const CIS_AMPELVERWALTUNG_URL = CIS_ROOT. "cis/index.php?menu=".
|
||||
CIS_ROOT. "cis/menu.php?content_id=&content=".
|
||||
CIS_ROOT. "cis/private/tools/ampelverwaltung.php";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -25,39 +26,12 @@ class AmpelMail extends FHC_Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Allow script execution only from CLI
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
|
||||
echo "Jobs must be run from the CLI";
|
||||
exit;
|
||||
}
|
||||
$this->CIS_AMPELVERWALTUNG_URL = CIS_ROOT. "cis/index.php?menu=".
|
||||
CIS_ROOT. "cis/menu.php?content_id=&content=".
|
||||
CIS_ROOT. "cis/private/tools/ampelverwaltung.php";
|
||||
// Load helpers
|
||||
$this->load->helper('hlp_sancho');
|
||||
|
||||
// Load models
|
||||
$this->load->model('content/Ampel_model', 'AmpelModel');
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
// Load helpers
|
||||
$this->load->helper('hlp_sancho');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function index as help
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php index.ci.php jobs/AmpelMail generateAmpelMail";
|
||||
|
||||
echo $result. PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +184,7 @@ class AmpelMail extends FHC_Controller
|
||||
'uid' => $uid,
|
||||
'firstName' => $firstName,
|
||||
'ampel_list' => $html_text,
|
||||
'link' => $this->CIS_AMPELVERWALTUNG_URL
|
||||
'link' => self::CIS_AMPELVERWALTUNG_URL
|
||||
);
|
||||
}
|
||||
return $ampel_data_arr;
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
*
|
||||
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
|
||||
*/
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class LVPlanJob extends FHC_Controller
|
||||
class LVPlanJob extends CLI_Controller
|
||||
{
|
||||
/**
|
||||
* Initialize LVPlanJob Class
|
||||
@@ -29,32 +28,7 @@ class LVPlanJob extends FHC_Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// An empty array as parameter will ensure that this controller is ONLY callable from command line
|
||||
parent::__construct(array());
|
||||
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
|
||||
echo "Jobs must be run from the CLI";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function index as help
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php ".$this->config->item('index_page')." jobs/LVPlanJob AddDirectGroups";
|
||||
|
||||
echo $result.PHP_EOL;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,7 @@ if (! defined('BASEPATH'))
|
||||
* Database Class
|
||||
*
|
||||
*/
|
||||
|
||||
class Prestudentstatus extends FHC_Controller
|
||||
class Prestudentstatus extends CLI_Controller
|
||||
{
|
||||
/**
|
||||
* Initialize Prestudentstatus Class
|
||||
@@ -17,32 +16,7 @@ class Prestudentstatus extends FHC_Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// An empty array as parameter will ensure that this controller is ONLY callable from command line
|
||||
parent::__construct(array());
|
||||
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
|
||||
echo "Jobs must be run from the CLI";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function index as help
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php ".$this->config->item('index_page')." jobs/Prestudentstatus CorrectStudienplan";
|
||||
|
||||
echo $result.PHP_EOL;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class ReihungstestJob extends FHC_Controller
|
||||
class ReihungstestJob extends CLI_Controller
|
||||
{
|
||||
private $VILESCI_RT_VERWALTUNGS_URL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -13,20 +11,6 @@ class ReihungstestJob extends FHC_Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Allow script execution only from CLI
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
|
||||
echo "Jobs must be run from the CLI";
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->VILESCI_RT_VERWALTUNGS_URL = site_url('/organisation/Reihungstest');
|
||||
|
||||
// Load models
|
||||
$this->load->model('crm/Reihungstest_model', 'ReihungstestModel');
|
||||
$this->load->model('crm/RtStudienplan_model', 'RtStudienplanModel');
|
||||
@@ -38,18 +22,8 @@ class ReihungstestJob extends FHC_Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function index as help
|
||||
*
|
||||
* @return void
|
||||
* runReihungstestJob
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php index.ci.php jobs/ReihungstestJob runReihungstestInfo";
|
||||
|
||||
echo $result. PHP_EOL;
|
||||
}
|
||||
|
||||
public function runReihungstestJob()
|
||||
{
|
||||
// Get study plans that have no assigned placement tests yet
|
||||
@@ -92,6 +66,9 @@ class ReihungstestJob extends FHC_Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* runZentraleReihungstestAnmeldefristAssistenzJob
|
||||
*/
|
||||
public function runZentraleReihungstestAnmeldefristAssistenzJob()
|
||||
{
|
||||
// Get placement tests where registration date was yesterday
|
||||
@@ -198,7 +175,6 @@ class ReihungstestJob extends FHC_Controller
|
||||
$mailcontent .= '<p style="font-family: verdana, sans-serif;"><a href="mailto:?bcc=' . $mailReceipients . '">Mail an alle schicken</a></p>';
|
||||
}
|
||||
$mailcontent_data_arr['table'] = $mailcontent;
|
||||
//$mailcontent_data_arr['link'] = $this->VILESCI_RT_VERWALTUNGS_URL;
|
||||
|
||||
// Send email in Sancho design
|
||||
if (!isEmptyString($mailcontent))
|
||||
@@ -215,7 +191,9 @@ class ReihungstestJob extends FHC_Controller
|
||||
}
|
||||
}
|
||||
|
||||
// Checks, if an applicant was assigned to a test after Anmeldefrist
|
||||
/**
|
||||
* Checks, if an applicant was assigned to a test after Anmeldefrist
|
||||
*/
|
||||
public function runZentraleReihungstestNachtraeglichHinzugefuegtJob()
|
||||
{
|
||||
// Get applicants that have been added to a test after Anmeldefrist
|
||||
@@ -315,6 +293,9 @@ class ReihungstestJob extends FHC_Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* runRemindApplicantsOfPlacementTestJob
|
||||
*/
|
||||
public function runRemindApplicantsOfPlacementTestJob()
|
||||
{
|
||||
// Get placement tests with testdate within 3 working days
|
||||
@@ -473,8 +454,7 @@ class ReihungstestJob extends FHC_Controller
|
||||
// Set associative array with the prepared HTML tables and URL be used by the template's variables
|
||||
$content_data_arr['studienplan_list'] = $studienplan_list;
|
||||
$content_data_arr['freie_plaetze_list'] = $freie_plaetze_list;
|
||||
$content_data_arr['link'] = $this->VILESCI_RT_VERWALTUNGS_URL;
|
||||
;
|
||||
$content_data_arr['link'] = site_url('/organisation/Reihungstest');
|
||||
|
||||
return $content_data_arr;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class CLI_Controller extends FHC_Controller
|
||||
{
|
||||
const INFO_FORMAT = '%s %s %s %s'; // Info message format
|
||||
const REQUIRED_PARAM_FORMAT = ' %s'; // Info message required method parameter format
|
||||
const OPTIONAL_PARAM_FORMAT = ' (%s)'; // Info message optional method parameter format
|
||||
const BLACKLIST_METHODS = array('__construct', 'index', 'get_instance'); // Methods to NOT display with _printHelp
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Checks if the controller is called from command line
|
||||
$this->_isAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
* By default the index is used to print the help message to explain how to call them from command line
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->printHelp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the public methods of the called controller and display
|
||||
* a help message to explain how to call them from command line
|
||||
*/
|
||||
protected function printHelp()
|
||||
{
|
||||
$this->load->library('EPrintfLib'); // loads the EPrintfLib to format the output
|
||||
|
||||
$this->eprintflib->printInfo('The following are the available commands:');
|
||||
$this->eprintflib->printInfo('');
|
||||
|
||||
// Gets a list of public methods of the called controller
|
||||
$reflectionClass = new ReflectionClass($this->router->class);
|
||||
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
// Loops through them
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
// Disascard the black listed methods
|
||||
if (!in_array($method->name, self::BLACKLIST_METHODS))
|
||||
{
|
||||
// Formatted message
|
||||
$info = sprintf(
|
||||
self::INFO_FORMAT, // Message format
|
||||
PHP_BINARY, // PHP binary name
|
||||
index_page(), // CI index page name
|
||||
$this->router->class, // The called controller name
|
||||
$method->name // The called controller current method name
|
||||
);
|
||||
|
||||
// Retrieves the parameter names for the current method
|
||||
$reflectionMethod = new ReflectionMethod($this->router->class, $method->name);
|
||||
$parameters = $reflectionMethod->getParameters();
|
||||
|
||||
// Loops through them
|
||||
foreach ($parameters as $parameter)
|
||||
{
|
||||
$info .= sprintf(
|
||||
$parameter->isOptional() ? self::OPTIONAL_PARAM_FORMAT : self::REQUIRED_PARAM_FORMAT, // Parameter message format required/optional
|
||||
$parameter->getName() // Current method parameter name
|
||||
);
|
||||
}
|
||||
|
||||
// Print the info message
|
||||
$this->eprintflib->printInfo($info);
|
||||
$this->eprintflib->printInfo('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the controller is called from the command line, if NOT the execution is immediately stopped
|
||||
*/
|
||||
private function _isAllowed()
|
||||
{
|
||||
if (!$this->input->is_cli_request())
|
||||
{
|
||||
$this->output->set_status_header(REST_Controller::HTTP_UNAUTHORIZED);
|
||||
|
||||
$this->load->library('EPrintfLib'); // loads the EPrintfLib to format the output
|
||||
|
||||
// Prints the main error message
|
||||
$this->eprintflib->printError('You are not authorized to access this content');
|
||||
// Prints the called controller name
|
||||
$this->eprintflib->printInfo('Controller name: '.$this->router->class);
|
||||
// Prints the called controller method name
|
||||
$this->eprintflib->printInfo('Method name: '.$this->router->method);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user