Commit dfe6dfee authored by Dainis Abols's avatar Dainis Abols
Browse files

Typo3 v11 remake

- added type classes
- change LDAP out methods
- version bump 3.0
parent 85cb38a3
<?php
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
/**
* RequestType type
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 01.02.2022
*/
class RequestType
{
use LoggerAwareTrait, TypeMethods;
const BE = 'be';
const FE = 'fe';
/**
* Request type value
*
* @var string
*/
public string $value;
/**
* Validates value
*
* @param $value
* @return mixed
*/
private function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::REQUEST_TYPE_EMPTY);
}
if (!in_array($value, [RequestType::BE, RequestType::FE])) {
$this->logger->info(sprintf(TypeErrors::REQUEST_TYPE_INVALID, $value));
}
return $value;
}
/**
* Creates a valid `request_type`
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
<?php
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
/**
* Table type
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 01.02.2022
*/
class Table
{
use LoggerAwareTrait, TypeMethods;
/**
* Database Table value
*
* @var string
*/
public string $value;
/**
* Validates value
*
* @param $value
* @return mixed
*/
private function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::TABLE_NAME_EMPTY);
}
return $value;
}
/**
* Creates a valid `Table` name
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
<?php
namespace Lu\LuApi\Types;
/**
* Username type
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 01.02.2022
*/
class TypeErrors
{
const USERNAME_EMPTY = "Empty username provided";
const TABLE_NAME_EMPTY = "Empty database table provided";
const REQUEST_TYPE_EMPTY = "Empty request type provided";
const REQUEST_TYPE_INVALID = "Invalid request type provided [%s]";
}
\ No newline at end of file
<?php
namespace Lu\LuApi\Types;
/**
* Type methods
*/
trait TypeMethods
{
/**
* Check if type value matches provided
*
* @param $value
* @return bool
*/
public function equals($value): bool
{
return $value == $this->value;
}
/**
* Check if value is empty
*
* @return bool
*/
public function empty(): bool
{
return empty($this->value);
}
}
<?php
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
/**
* Username type
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 01.02.2022
*/
class Username
{
use LoggerAwareTrait, TypeMethods;
/**
* Username value
*
* @var string
*/
public string $value;
/**
* Validates value
*
* @param $value
* @return mixed
*/
private function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::USERNAME_EMPTY);
}
return $value;
}
/**
* Creates a valid `username`
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
Add to composer, when tests finished!
```
"autoload-dev": {
"psr-4": {
"Lu\\LuApi\\Tests\\": "Tests"
}
},
```
\ No newline at end of file
......@@ -22,7 +22,7 @@ if (PHP_SAPI !== 'cli') {
// Get options
$shortopts = "";
$longopts = [
$longopts = [
"strdjaunais:", // kont.strd_jaunais file location
"xmluzv:", // kont.xmluzv_jaunais file location
"contactcv:", // CV XML file location
......@@ -39,7 +39,7 @@ $help = "Usage:
--xmlekajaunais xmlekajaunais XML file location\n\n";
$luisFileLocation = 'https://luis.lu.lv/pls/pub/lu_portals.foto_print';
$photoFileResize = 1000;
$photoFileResize = 1000;
if (empty($options)) {
echo "\n";
......@@ -84,25 +84,25 @@ if (!empty($options['xmlekajaunais'])) {
}
// Include dependency
require __DIR__.'/../../../../vendor/autoload.php';
require __DIR__ . '/../../../../vendor/autoload.php';
//======================================================================================================================
// Prepare persons array
$xml = simplexml_load_file($xmluzvPath);
$xml = simplexml_load_file($xmluzvPath);
// Stop and make invalid json, if XML read failed
if (empty($xml)) {
mail('dainis.abols@lu.lv', 'CONTACTS SYNC ERR: No sync data received', date('Y.m.d H:i:s')." XML real failed!");
mail('dainis.abols@lu.lv', 'CONTACTS SYNC ERR: No sync data received', date('Y.m.d H:i:s') . " XML real failed!");
die;
}
$xmlCv = simplexml_load_file($contactcvPath);
$xmlCv = simplexml_load_file($contactcvPath);
$cvData = [];
foreach ($xmlCv as $entry) {
$personId = (string)$entry->attributes()->ID;
$rawXML = str_replace('<![CDATA[', "", $entry);
$rawXML = str_replace(']]>', "", $rawXML);
$personId = (string)$entry->attributes()->ID;
$rawXML = str_replace('<![CDATA[', "", $entry);
$rawXML = str_replace(']]>', "", $rawXML);
$cvData[$personId] = (string)$rawXML;
}
......@@ -122,8 +122,8 @@ foreach ($xml as $node) {
$positions = [];
if (!empty($person->amati->amats)) {
foreach ($person->amati->amats as $position) {
$_position = [
'id' => SOLR_PREFIX_POSITION.uniqid(),
$_position = [
'id' => SOLR_PREFIX_POSITION . uniqid(),
'type' => 'position',
'unit_ids' => (string)$position->strukt->attributes()->id,
'name' => (string)$position->nosaukums,
......@@ -136,7 +136,7 @@ foreach ($xml as $node) {
if (!empty($person->darba_vietas->d_vieta)) {
foreach ($person->darba_vietas->d_vieta as $place) {
$_workPlace = [
'id' => SOLR_PREFIX_WORKPLACE.uniqid(),
'id' => SOLR_PREFIX_WORKPLACE . uniqid(),
'type' => 'workplace',
];
if (!empty($place->adrese)) {
......@@ -153,7 +153,7 @@ foreach ($xml as $node) {
}
$old_id = (int)$person->attributes()->old_id;
$tmp = [
$tmp = [
'id' => (string)$person->attributes()->id,
'type' => 'person',
'old_id' => $old_id,
......@@ -162,7 +162,7 @@ foreach ($xml as $node) {
];
// Load extra data (currently person consultation)
$ExtraData = @file_get_contents('https://luis.lu.lv/pls/lu/JC_XML.persona?p_ckods='.$old_id, false, $extraContext);
$ExtraData = @file_get_contents('https://luis.lu.lv/pls/lu/JC_XML.persona?p_ckods=' . $old_id, false, $extraContext);
if ($ExtraData) {
$use_errors = libxml_use_internal_errors(true);
$ExtraXml = simplexml_load_string($ExtraData);
......@@ -184,11 +184,11 @@ foreach ($xml as $node) {
// Get absence information
if (!empty($person->prombutne)) {
if (!empty($person->prombutne->no)) {
$xmlDate = DateTime::createFromFormat('d.m.Y H:i:s', (string)$person->prombutne->no.' 00:00:00');
$xmlDate = DateTime::createFromFormat('d.m.Y H:i:s', (string)$person->prombutne->no . ' 00:00:00');
$tmp['absence_from'] = $xmlDate->format(DateTime::ISO8601);
}
if (!empty($person->prombutne->lidz)) {
$xmlDate = DateTime::createFromFormat('d.m.Y H:i:s', (string)$person->prombutne->lidz.' 23:59:59');
$xmlDate = DateTime::createFromFormat('d.m.Y H:i:s', (string)$person->prombutne->lidz . ' 23:59:59');
$tmp['absence_to'] = $xmlDate->format(DateTime::ISO8601);
}
if (!empty($person->prombutne->apraksts)) {
......@@ -198,19 +198,25 @@ foreach ($xml as $node) {
// Get photo
if (!empty($person->foto)) {
$file_path = $luisFileLocation.'?p_kods='.urlencode((string)$person->foto);
$client = new GuzzleHttp\Client();
$file_path = $luisFileLocation . '?p_kods=' . urlencode((string)$person->foto);
$client = new GuzzleHttp\Client();
try {
$result = $client->get($file_path, ['verify' => false]);
$type = pathinfo($file_path, PATHINFO_EXTENSION);
$result = $client->get($file_path, ['verify' => false]);
$type = pathinfo($file_path, PATHINFO_EXTENSION);
$content = $result->getBody()->getContents();
$cData = resizeImage($content, $photoFileResize, $file_path);
$cData = resizeImage($content, $photoFileResize, $file_path);
} catch (\Exception $e) {
$content = null;
$cData = null;
@mail(
"dainisa@lu.lv",
"Image download/parse error <{$luisFileLocation}?p_kods=".urlencode((string)$person->foto).">",
print_r($e, true)
);
}
if ($cData) {
$tmp['photo'] = 'data:image/'.$cData[1].';base64,'.base64_encode($cData[0]);
$tmp['photo'] = 'data:image/' . $cData[1] . ';base64,' . base64_encode($cData[0]);
}
}
......@@ -249,7 +255,7 @@ $units = [];
* Load unit data
*
* @param $xml
* @param int $counter
* @param int $counter
* @param null $parentId
*/
function loadUnits($xml, $counter = 0, $parentId = null)
......@@ -261,8 +267,8 @@ function loadUnits($xml, $counter = 0, $parentId = null)
$counter++;
// Calculate current and next level names
$level = $key.$counter;
$next_level = $key.($counter + 1);
$level = $key . $counter;
$next_level = $key . ($counter + 1);
// Check all items in current level
foreach ($xml->$level as $item) {
......@@ -281,7 +287,7 @@ function loadUnits($xml, $counter = 0, $parentId = null)
$personIds = [];
foreach ($item->persona as $person) {
$personId = (string)$person->attributes()->id;
$personId = (string)$person->attributes()->id;
$personIds[$personId] = $personId;
// And also save person unit
$persons[$personId]['unit_ids'][$unitId] = $unitId;
......@@ -322,12 +328,12 @@ function loadAddreses($xml, $addressId, $counter = 0)
// Pre-set initial values
$_data = [];
$key = 'STRUKT';
$key = 'STRUKT';
$counter++;
// Calculate current and next level names
$level = $key.$counter;
$next_level = $key.($counter + 1);
$level = $key . $counter;
$next_level = $key . ($counter + 1);
// Check all items in current level
foreach ($xml->$level as $item) {
......@@ -335,7 +341,7 @@ function loadAddreses($xml, $addressId, $counter = 0)
// If person found, add to response
foreach ($item->persona as $person) {
// Save person address id
$personId = (string)$person->attributes()->id;
$personId = (string)$person->attributes()->id;
$persons[$personId]['address_ids'][$addressId] = $addressId;
// And append Unit code if real person exist
......@@ -364,9 +370,9 @@ function loadAddreses($xml, $addressId, $counter = 0)
function resizeImage($data, $square_size, $file_path)
{
$result = @getimagesizefromstring($data);
$width = @$result[0];
$width = @$result[0];
$height = @$result[1];
$mtype = @$result['mime'];
$mtype = @$result['mime'];
$allowed_ext = [
'image/gif',
......@@ -387,10 +393,10 @@ function resizeImage($data, $square_size, $file_path)
// Resize only if original is larger then allowed
if ($ratio < 1) {
$new_width = $width * $ratio;
$new_width = $width * $ratio;
$new_height = $height * $ratio;
} else {
$new_width = $width;
$new_width = $width;
$new_height = $height;
}
......@@ -415,7 +421,7 @@ function resizeImage($data, $square_size, $file_path)
// Loop through all addresses
foreach ($xml as $item) {
// Create address ID
$addressId = SOLR_PREFIX_ADDRESS.hash('crc32b', (string)$item->attributes()->NOSAUK);
$addressId = SOLR_PREFIX_ADDRESS . hash('crc32b', (string)$item->attributes()->NOSAUK);
// Create initial array
$tmp = [
......
{
"name": "luitd/lu-api",
"version": "2.9.0",
"version": "3.0.0",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......@@ -16,8 +16,10 @@
],
"license": "GPL-3.0-or-later",
"require": {
"typo3/cms-core": "^9.5 || ^10",
"fluidtypo3/vhs": "^6"
"typo3/cms-core": "^11.5"
},
"require-dev": {
"typo3/cms-install": "^11.5"
},
"autoload": {
"psr-4": {
......@@ -33,15 +35,14 @@
},
"scripts": {
"post-autoload-dump": [
"mkdir -p .Build/Web/typo3conf/ext/",
"[ -L .Build/Web/typo3conf/ext/lu_api ] || ln -snvf ../../../../. .Build/Web/typo3conf/ext/lu_api"
"TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare"
]
},
"extra": {
"typo3/cms": {
"extension-key": "lu_api",
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": ".Build/Web"
"app-dir": ".Build",
"web-dir": ".Build/public"
}
}
}
}
\ 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.9.0',
'version' => '3.0.0',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......@@ -23,7 +23,7 @@ $EM_CONF[$_EXTKEY] = [
'author_company' => 'University of Latvia',
'constraints' => [
'depends' => [
'typo3' => '9.5.99-10.9.99',
'typo3' => '11.5.0-11.99.99',
],
],
'autoload' => [
......
......@@ -4,11 +4,11 @@
## Version
2.9.0
3.0.0
## Dependencies
TYPO3 9.5+ | v10+
* TYPO3 11+
## Author
......
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