Commit 036f9d3b authored by Dainis Abols's avatar Dainis Abols
Browse files

Added get_luis_data and added loadActivePages event

Version 2.6.2
parent 614901b4
<?php
/**
* šis fails izveidots kursa kataloga Solr instancēm datu ielādei no LUIS. Sorl nemāk lasīt failus, kas ir aizsargāti
* ar http basic authentication, tāpēc nolasīšanas autorizācijai tika izveidots šis fails, kas saņem pieprasījumā
* no Sorl datu ielades skriptiem LUIS faila adresi parametrā 'remote_url', nolasa failu, atgriež nolasīto saturu.
* Sis fails tika novietots direktorijā <typo3home>/typo3/, jo šajā direktorijā ir PHP izpildes tiesības
**/
function getRemoteData($url)
{
$curl = curl_init($url);
$config = require '/home/portal/typo3/typo3conf/LocalConfiguration.php';
$auth = $config['EXTENSIONS']['lu_api']['solrDatabase']['LuisUser'].":".$config['EXTENSIONS']['lu_api']['solrDatabase']['LuisPass'];
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($curl);
$resultStatus = curl_getinfo($curl);
return $response;
}
$url = $_GET['remote_url'];
$url = urldecode($url);
$xml = getRemoteData($url);
echo $xml;
<?php
// Check if cli is used, die if not
if (PHP_SAPI !== 'cli') {
return;
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/**
* Class loadActivePages
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @since 28.09.2020
* @version 1.0
*/
class loadActivePages
{
/**
* DB Connection
*
* @var \mysqli
*/
private $mysqli;
/**
* Array of executed query string
*
* @var array
*/
private $executedQueries = [];
/**
* Used table name
*
* @var string
*/
private $tableName = "tx_working_uids";
/**
* List of valid pids
*
* @var array
*/
private $validUids = [];
/**
* loadActivePages constructor.
* Loads configuration and creates connection
*/
public function __construct()
{
// Fetch config file
$config = require '/home/portal/typo3/typo3conf/LocalConfiguration.php';
// Open connection
$this->mysqli = new mysqli($config['DB']['Connections']['Default']['host'], $config['DB']['Connections']['Default']['user'], $config['DB']['Connections']['Default']['password'], $config['DB']['Connections']['Default']['dbname']);
}
/**
* Loads all pages
*/
public function loadAllPages()
{
// Define query
$query = "SELECT uid, pid
FROM pages
WHERE (`starttime` = 0 OR UNIX_TIMESTAMP() >= `starttime`) AND (`endtime` = 0 OR `endtime` >= UNIX_TIMESTAMP()) AND `hidden` = 0 AND `deleted` = 0";
if ($result = $this->executeQuery($query)) {
while ($row = $result->fetch_object()) {
if ($this->findValidTree($row->pid)) {
$this->validUids[] = $row->uid ;
}
}
}
}
/**
* Find duplicates
*/
public function findValidTree($pid)
{
$query = "SELECT pid FROM pages WHERE uid = {$pid} AND (`starttime` = 0 OR UNIX_TIMESTAMP() >= `starttime`) AND (`endtime` = 0 OR `endtime` >= UNIX_TIMESTAMP()) AND `hidden` = 0 AND `deleted` = 0";
if ($result = $this->executeQuery($query)) {
while ($row = $result->fetch_object()) {
if ($row->pid == 0 || $this->findValidTree($row->pid)) {
return true;
}
}
}
return false;
}
/**
* Insert found IDs
*/
public function insertData()
{
// Check if any duplicates available
if (empty($this->validUids)) {
die('No pids gathered, terminating');
}
// Clear out previous data
$this->executeQuery("TRUNCATE {$this->tableName};");
// Insert new data
// Update DB for found IDs
$tmpq = [];
$query = "INSERT INTO {$this->tableName} (uid) VALUES ";
foreach($this->validUids as $uid) {
$tmpq[] = "(".$uid.")";
}
$query .= implode(",", $tmpq);
$this->executeQuery($query);
}
/**
* Saves executed queries
*
* @param $query
*
* @return bool|\mysqli_result
*/
private function executeQuery($query) {
$this->executedQueries[] = $query;
return $this->mysqli->query($query);
}
}
// Execute scripts
$cls = new loadActivePages();
$cls->loadAllPages();
$cls->insertData();
{
"name": "luitd/lu-api",
"version": "2.6.1",
"version": "2.6.2",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......@@ -16,7 +16,8 @@
],
"license": "GPL-3.0-or-later",
"require": {
"typo3/cms-core": "^9.5 || ^10"
"typo3/cms-core": "^9.5 || ^10",
"vhs": "^6.0"
},
"autoload": {
"psr-4": {
......
......@@ -40,5 +40,11 @@ solrDatabase.purchasesList = lupurchases
# cat=SOLR/set; type=string; label=Regulations (Normative Acts) list DB
solrDatabase.regulations = db
# cat=SOLR/set; type=string; label=LUIS User for XML requests
solrDatabase.LuisUser =
# cat=SOLR/set; type=string; label=LUIS User password for XML requests
solrDatabase.LuisPass =
# cat=StorageDIR/set; type=string; label=Purchases file storage directory path
storage.lupurchases = /home/portal/typo3data/storage/purchases/
\ No newline at end of file
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'title' => 'LU API',
'description' => 'REST API Integration for TYPO3',
'category' => 'plugin',
'version' => '2.6.1',
'version' => '2.6.2',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -6,3 +6,10 @@ CREATE TABLE `tx_namedays` (
`name` VARCHAR(100) DEFAULT NULL,
KEY `namedate` (`namedate`, `name`)
);
#
# Table structure for table `tx_working_uids`
#
CREATE TABLE `tx_working_uids` (
`uid` INTEGER DEFAULT 0
);
......@@ -4,7 +4,7 @@
## Version
2.6.1
2.6.2
## Dependencies
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment