Skip to content
Commits on Source (5)
vendor
composer.lock
\ No newline at end of file
# PlagScanCron
This Cron Provides a periodical check of all plagiarism checks against the PlagScan API through the **PlagScanExercise** plugin.
## Requirements
* PHP: [![PHP Version](https://img.shields.io/badge/PHP-7.4.x-blue.svg)](https://php.net/)
* ILIAS: [![ILIAS Version](https://img.shields.io/badge/ILIAS-8.x-orange.svg)](https://ilias.de/)
* ILIAS: [![Plugin PlagScanExercise](https://img.shields.io/badge/PlagScanExercise-1.2.x-orange.svg)](https://gitlab.databay.de/PlagScan/PlagScanExercise)
## Installation
Before installing the plugin ensure all requirements are given.
1. Clone this repository to **<YOUR_ILIAS>/Customizing/global/plugins/Services/Cron/CronHook**
2. Enter the repository and do **composer install**
3. Login to ILIAS with an administrator account (e.g. root)
4. Select **Plugins** from the **Administration** main menu drop down.
5. Search for the **PlagScanCron** plugin in the list of plugin and choose **Install** from the **Actions** drop down.
## Configuration
After installation the plugin can be activated within the ILIAS Plugin Administration overview.
After the activation the plugins cron job appears within the ILIAS Cron Jobs (Administration >> General Settings >> Cron Jobs).
From there it can be disabled, executed and its settings can be changed.
Beside the core settings of the cron shedule this job offer 3 custom settings:
- **Activation of PlagScan Cron** enables the cron job from plugin side.
- **Activate Hotrun** enables the communication with the required Plugin and therefor the PlagScan API. If not checked a dry run is executed without any external requests and therefore without functionality.
- **Protocol** activates a protocol log for the exectued cron job.
## Usage
None
## Specifications
None
## Correlation
None
#### Known Issues
None
<?php
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);
namespace ILIAS\Plugin\PlagScanCron;
use ilCheckboxInputGUI;
use ilCronJob;
use ilCronJobResult;
use ilCronManager;
use ilCronManagerImpl;
use ilDBInterface;
use ILIAS\Plugin\PlagScanExercise\PlagScan\DocumentManagement;
use ilPlagScanCronPlugin;
use ilPropertyFormGUI;
use ilSetting;
use ilUtil;
class Task extends ilCronJob
{
protected ilPlagScanCronPlugin $plugin;
protected ilSetting $settings;
private ilCronManager $cron_manager;
protected bool $hotrun = false;
protected bool $protocol = false;
public function __construct()
{
global $DIC;
$this->plugin = ilPlagScanCronPlugin::getInstance();
$this->settings = new ilSetting('psxcron');
$this->cron_manager = $DIC->cron()->manager();
$this->hotrun = (bool) $this->settings->get('hotrun', '');
$this->protocol = (bool) $this->settings->get('protocol', '');
}
public function getId(): string
{
return 'psxcron_job';
}
public function hasAutoActivation(): bool
{
return true;
}
public function hasFlexibleSchedule(): bool
{
return true;
}
public function getDefaultScheduleType(): int
{
return self::SCHEDULE_TYPE_IN_MINUTES;
}
public function getDefaultScheduleValue(): int
{
return 5;
}
public function hasCustomSettings(): bool
{
return true;
}
public function addCustomSettingsToForm(ilPropertyFormGUI $form): void
{
$activate = new ilCheckboxInputGUI($this->plugin->txt('sysconf_activate'), 'activation');
$activate->setInfo($this->plugin->txt('sysconf_activate_info'));
$activate->setChecked((bool) $this->settings->get('activation'));
$form->addItem($activate);
$hotrun = new ilCheckboxInputGUI($this->plugin->txt('hotrun'), 'hotrun');
$hotrun->setInfo($this->plugin->txt('hotrun_info'));
$hotrun->setChecked((bool) $this->settings->get('hotrun'));
$form->addItem($hotrun);
$protocol = new ilCheckboxInputGUI($this->plugin->txt('protocol'), 'protocol');
$protocol->setInfo($this->plugin->txt('protocol_info'));
$protocol->setChecked((bool) $this->settings->get('protocol'));
$form->addItem($protocol);
}
public function saveCustomSettings(ilPropertyFormGUI $form): bool
{
$this->settings->set('activation', $form->getInput('activation'));
$this->settings->set('hotrun', $form->getInput('hotrun'));
$this->settings->set('protocol', $form->getInput('protocol'));
return true;
}
public function activationWasToggled(ilDBInterface $db, ilSetting $setting, bool $currently_active): void
{
$this->settings->set('activation', $currently_active ? '1' : '0');
parent::activationWasToggled($db, $setting, $currently_active);
}
public function getTitle(): string
{
return $this->plugin->txt('cronjob_title');
}
public function getDescription(): string
{
$txt = $this->plugin->txt('cronjob_description');
$txt .= '<br /><em>' . $this->plugin->txt('cronjob_status') . '</em>';
if ($this->settings->get('hotrun', '0') === '1') {
$txt .= ' ' . $this->plugin->txt('hotrun_active');
} else {
$txt .= ' ' . $this->plugin->txt('dryrun_active');
}
return $txt;
}
public function run(): ilCronJobResult
{
$this->cron_manager->ping($this->getId());
if ($this->hotrun) {
DocumentManagement::checkAllDocuments();
$this->cron_manager->ping($this->getId());
DocumentManagement::updateAllDocuments();
$this->cron_manager->ping($this->getId());
}
$this->cron_manager->ping($this->getId());
$result = new ilCronJobResult();
$result->setStatus(ilCronJobResult::STATUS_OK);
return $result;
}
}
<?php
/**
* @category PlagScanCron
* @package PlagScan
* @author Maximilian Becker <mbecker@databay.de>
* @copyright 2019 Maximilian Becker / Databay AG
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://www.databay.de Databay AG
*/
// @codingStandardsIgnoreStart
require_once './Services/Cron/classes/class.ilCronJob.php';
require_once './Services/Cron/classes/class.ilCronJobResult.php';
// @codingStandardsIgnoreEnd
/**
* Class ilPlagScanCronCronJob
*/
class ilPlagScanCronCronJob extends ilCronJob
{
const SCHEDULE_TYPE_DAILY = 1;
const SCHEDULE_TYPE_IN_MINUTES = 2;
const SCHEDULE_TYPE_IN_HOURS = 3;
const SCHEDULE_TYPE_IN_DAYS = 4;
const SCHEDULE_TYPE_WEEKLY = 5;
const SCHEDULE_TYPE_MONTHLY = 6;
const SCHEDULE_TYPE_QUARTERLY = 7;
const SCHEDULE_TYPE_YEARLY = 8;
public $hotrun = false;
public $protocol = false;
public $protocol_handle = null;
public $protocol_handle2 = null;
public function __construct()
{
$settings = new ilSetting('psxcron');
$this->hotrun = (bool) $settings->get('hotrun', 0);
$this->protocol = (bool) $settings->get('protocol', 0);
}
/**
* @return string Returns the ID of the cronjob
*/
public function getId()
{
return 'psxcron_job';
}
/**
* @return bool Return is the cronjob is automatically activated
*/
public function hasAutoActivation()
{
return true;
}
/**
* @return bool Returns if the cronjob has a flexible schedule
*/
public function hasFlexibleSchedule()
{
return true;
}
/**
* @return int Returns the default schedule type of the cronjob
*/
public function getDefaultScheduleType()
{
return self::SCHEDULE_TYPE_IN_MINUTES;
}
/**
* @return mixed Returns the default schedule value (or void)
*/
public function getDefaultScheduleValue()
{
return 5;
}
/**
* @return bool Returns of the cronjob has custom settings
*/
public function hasCustomSettings()
{
return true;
}
/**
* @param ilPropertyFormGUI $form Form object
*
* @return void
*/
public function addCustomSettingsToForm( ilPropertyFormGUI $form )
{
global $lng;
$settings = new ilSetting('psxcron');
$activate_checkbox = new ilCheckboxInputGUI( $lng->txt( 'cron_crnhk_psxcron_sysconf_activate' ), "activation" );
$activate_checkbox->setInfo( $lng->txt( 'cron_crnhk_psxcron_sysconf_activate_info' ) );
$activate_checkbox->setChecked( (bool)$settings->get( 'activation', false ) );
$form->addItem( $activate_checkbox );
$hotrun_checkbox = new ilCheckboxInputGUI($lng->txt('cron_crnhk_psxcron_hotrun'), 'hotrun');
$hotrun_checkbox->setInfo($lng->txt('cron_crnhk_psxcron_hotrun_info'));
$hotrun_checkbox->setChecked( (bool)$settings->get( 'hotrun', false ) );
$form->addItem($hotrun_checkbox);
$protocol_checkbox = new ilCheckboxInputGUI($lng->txt('cron_crnhk_psxcron_protocol'), 'protocol');
$protocol_checkbox->setInfo($lng->txt('cron_crnhk_psxcron_protocol_info'));
$protocol_checkbox->setChecked( (bool)$settings->get( 'protocol', false ) );
$form->addItem($protocol_checkbox);
}
/**
* @param ilPropertyFormGUI $form Form object
*
* @return void
* @noinspection PhpMissingParentCallCommonInspection
*/
public function saveCustomSettings(ilPropertyFormGUI $form )
{
$settings = new ilSetting('psxcron');
$form->setValuesByPost();
$activation = $form->getItemByPostVar( 'activation' );
$settings->set( 'activation', (int)$activation->getChecked() );
$hotrun = $form->getItemByPostVar( 'hotrun' );
$settings->set( 'hotrun', (int)$hotrun->getChecked() );
$protocol = $form->getItemByPostVar( 'protocol' );
$settings->set( 'protocol', (int)$protocol->getChecked() );
return true;
}
/**
* @param bool $a_currently_active True if the cronjob is now active
*
* @return void
*/
public function activationWasToggled( $a_currently_active )
{
$settings = new ilSetting('psxcron');
$settings->set('activation', $a_currently_active);
parent::activationWasToggled( $a_currently_active );
}
/**
* @return string Returns a readable title for the cronjob
*/
public function getTitle()
{
global $lng;
$txt = $lng->txt('cron_crnhk_psxcron_cronjob_title');
return $txt;
}
/**
* @return string Returns a description of the cronjob
*/
public function getDescription()
{
global $lng;
$txt = $lng->txt('cron_crnhk_psxcron_cronjob_description');
$txt .= '<br /><em>'.$lng->txt('cron_crnhk_psxcron_cronjob_status').'</em>';
$settings = new ilSetting('psxcron');
if($settings->get('hotrun', 0) == 1)
{
$txt .= ' ' . $lng->txt('cron_crnhk_psxcron_hotrun_active');
}
else
{
$txt .= ' ' . $lng->txt('cron_crnhk_psxcron_dryrun_active');
}
$prepender = '';
$appender = '';
if($settings->get('protocol', 0) == 1)
{
if(file_exists(ilUtil::getWebspaceDir().'/psxcronlog.lastrun.txt'))
{
$prepender .= '<a href="'. ilUtil::getWebspaceDir().'/psxcronlog.lastrun.txt' .'" target="_blank">';
$appender = '</a>';
}
$txt .= ' / ' . $prepender . $lng->txt('cron_crnhk_psxcron_protocol_active') . $appender;
}
else
{
$txt .= ' / ' . $lng->txt('cron_crnhk_psxcron_protocol_inactive');
}
return $txt;
}
/**
* @return ilCronJobResult Result object
*/
public function run()
{
$this->startProtocol();
ilCronManager::ping($this->getId());
$this->writeDashline(2);
$this->writeProtocol('' . PHP_EOL);
if($this->hotrun) {
require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/PlagScanExercise/classes/class.ilPlagScanDocumentManagement.php';
ilPlagScanDocumentManagement::checkAllDocuments();
ilCronManager::ping($this->getId());
ilPlagScanDocumentManagement::updateAllDocuments();
ilCronManager::ping($this->getId());
}
ilCronManager::ping($this->getId());
$this->closeProtocol();
$result = new ilCronJobResult();
$result->setStatus(ilCronJobResult::STATUS_OK);
$result->setCode(0);
$result->setMessage('Done.');
return $result;
}
/**
* @return void
*/
public function startProtocol()
{
if($this->protocol)
{
$filepath = ilUtil::getWebspaceDir().'/psxcronlog.lastrun.txt';
//$filepath2 = ilUtil::getWebspaceDir().'/psxcronlog.' . date('Ymd_H:i:s', time() ) . '.txt';
$this->protocol_handle = fopen($filepath, 'w');
//$this->protocol_handle2 = fopen($filepath2, 'w');
}
}
/**
* @param string $message Message to be written.
*
* @return void
*/
public function writeProtocol($message)
{
if($this->protocol && $this->protocol_handle != null)
{
fwrite($this->protocol_handle, '[' . date("H:i:s", time() ) . '] ' . $message . PHP_EOL);
}
if($this->protocol && $this->protocol_handle2 != null)
{
fwrite($this->protocol_handle2, '[' . date("H:i:s", time() ) . '] ' . $message . PHP_EOL);
}
}
/**
* @param int $count Number of lines
* @param int $width Number of characters per line
* @param string $character Character (or group!) used for line
*
* @return void
*/
public function writeDashline($count = 1, $width = 80, $character = '-')
{
if($width < 0 )
{
$width = 0;
}
if($this->protocol && $this->protocol_handle != null)
{
fwrite($this->protocol_handle, str_repeat( str_repeat($character, $width).PHP_EOL, $count ));
}
if($this->protocol && $this->protocol_handle2 != null)
{
fwrite($this->protocol_handle2, str_repeat( str_repeat($character, $width).PHP_EOL, $count ));
}
}
/**
* @return void
*/
public function closeProtocol()
{
if($this->protocol && $this->protocol_handle != null)
{
fclose($this->protocol_handle);
}
if($this->protocol && $this->protocol_handle2 != null)
{
fclose($this->protocol_handle2);
}
}
}
\ No newline at end of file
<?php
/**
* @category PlagScanCron
* @package PlagScan
* @author Maximilian Becker <mbecker@databay.de>
* @copyright 2019 Maximilian Becker / Databay AG
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://www.databay.de Databay AG
*/
// @codingStandardsIgnoreStart
require_once './Services/Cron/classes/class.ilCronHookPlugin.php';
require_once './Customizing/global/plugins/Services/Cron/CronHook/PlagScanCron/classes/class.ilPlagScanCronCronJob.php';
// @codingStandardsIgnoreEnd
/**
* Class ilPlagScanCronPlugin
*/
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);
use ILIAS\Plugin\PlagScanCron\Task;
class ilPlagScanCronPlugin extends ilCronHookPlugin
{
/**
* @return string
*/
public function getPluginName()
{
return "PlagScanCron";
}
/**
* @return array Returns a list of instances
*/
public function getCronJobInstances()
{
$job = new ilPlagScanCronCronJob();
$result[] = $job;
return $result;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param string $a_job_id ID of the requested cronjob instance
*
* @return ilPlagScanCronCronJob Cronjob instance
*/
public function getCronJobInstance($a_job_id)
{
$retval = new ilPlagScanCronCronJob();
return $retval;
}
}
\ No newline at end of file
public const CTYPE = 'Services';
public const CNAME = 'Cron';
public const SLOT_ID = 'crnhk';
public const PNAME = 'PlagScanCron';
private static ?self $instance = null;
public static function getInstance(): self
{
if (self::$instance === null) {
global $DIC;
self::$instance = $DIC['component.factory']->getPlugin('psxcron');
}
return self::$instance;
}
public function getPluginName(): string
{
return self::PNAME;
}
public function getCronJobInstances(): array
{
return [new Task()];
}
public function getCronJobInstance(string $jobId): ilCronJob
{
return new Task();
}
}
<!-- language file start -->
cronjob_title#:#PlagScan Cron
cronjob_description#:#Cronjob für PlagScan.
cronjob_status#:#Status:
......
<!-- language file start -->
cronjob_title#:#PlagScan Cron
cronjob_description#:#Cronjob for PlagScan.
cronjob_status#:#Status:
......
<?php
/**
* @category PlagScanCron
* @package PlagScan
* @author Maximilian Becker <mbecker@databay.de>
* @copyright 2019 Maximilian Becker / Databay AG
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://www.databay.de Databay AG
*/
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);
$id = "psxcron";
$version = "1.0.0";
$ilias_min_version = "6.0";
$ilias_max_version = "6.999";
$responsible = "Maximilian Becker";
$responsible_mail = "mbecker@databay.de";
$id = 'psxcron';
$version = '1.2.0';
$ilias_min_version = '8.0';
$ilias_max_version = '8.999';
$responsible = 'Maximilian Becker';
$responsible_mail = 'mbecker@databay.de';