Commit 3f8943b1 authored by Dainis Abols's avatar Dainis Abols
Browse files

Added url slug for clean names and missing language strings

1.0.3
parent 7d20f9e3
......@@ -2,12 +2,12 @@
namespace Lu\LuNames\Command;
use Lu\LuNames\Domain\Model\Person;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Bootstrap;
......@@ -41,6 +41,7 @@ class ImportCommand extends Command
$inputFile = $input->getArgument('xlsxFile');
$storagePid = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('lu_names')['storage_page_id'];
$personModel = GeneralUtility::makeInstance(Person::class);
$db = new \PDO('mysql:host='.$config['DB']['Connections']['Default']['host'].';dbname='.$config['DB']['Connections']['Default']['dbname'], $config['DB']['Connections']['Default']['user'], $config['DB']['Connections']['Default']['password']);
......@@ -192,9 +193,12 @@ class ImportCommand extends Command
}
}
$slug = $personModel->generateSlug($personId, $row['B'], $row['E']);
$sourcesCount = empty($sources) ? '' : count(explode(' ', $sources));
$insert = '('.$personId.', '.$storagePid.', '.time().', '.time().', '.'0, '.'0, ';
$insert .= "'".implode("','", $row)."',";
$insert .= $occupationId.",".$familyStatusId.")";
$insert .= $occupationId.",".$familyStatusId.","."'".$slug."'".",".$sourcesCount.")";
$values[] = ['sources' => $sources, 'insert' => $insert, 'personId' => $personId];
}
......@@ -210,7 +214,7 @@ class ImportCommand extends Command
'INSERT INTO tx_lunames_domain_model_person (uid, pid, tstamp, crdate, cruser_id, deleted, family_name,
maiden_name, other_name, given_name, father, mother, place_of_birth, year_of_birth, day_of_birth, month_of_birth,
year_of_death, day_of_death, month_of_death, place_of_death, region, prewar_residence, war_residence, gender, spouse, fate,
comments, occupation,family_status)
comments, occupation, family_status, slug, source_codes)
VALUES '.implode(',',$insertValues)
);
$statement->execute();
......
......@@ -2,6 +2,8 @@
namespace Lu\LuNames\Domain\Model;
use TYPO3\CMS\Core\DataHandling\SlugHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
......@@ -350,4 +352,30 @@ class Person extends AbstractEntity
{
return $this->sourceCodes;
}
/**
* Generates slug field
*
* @param $uid
* @param $family_name
* @param $given_name
* @return string
*/
public function generateSlug($uid, $family_name, $given_name): string
{
$fieldConfig = $GLOBALS['TCA'][$this->tableName]['columns']['slug']['config'];
$slugHelper = GeneralUtility::makeInstance(SlugHelper::class,
$this->tableName,
'slug',
$fieldConfig
);
$data = [
'uid' => $uid,
'family_name' => $family_name,
'given_name' => $given_name
];
return $slugHelper->generate($data, $uid);
}
}
......@@ -3,8 +3,11 @@
namespace Lu\LuNames\Hooks;
use Lu\LuApi\DataSources\SolrSynchronize;
use Lu\LuNames\Domain\Model\Person;
use Lu\LuNames\Domain\Session\BackendSessionHandler;
use Lu\LuNames\Helpers\DataHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class TCEmainHook. Sync SOLR data on save, update, and delete events
......@@ -30,6 +33,22 @@ class TCEmainHook
public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, &$reference)
{
if ($table === 'tx_lunames_domain_model_person') {
// Prefix uid to slug field for newly created records
if ($status === 'new') {
$id = $reference->substNEWwithIDs[$id];
$personModel = GeneralUtility::makeInstance(Person::class);
$table = $personModel->getTableName();
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$connection->update(
$table,
[
'slug' => $personModel->generateSlug($id, $fieldArray['family_name'], $fieldArray['given_name']),
],
['uid' => $id]
);
}
$this->syncAndStore();
}
}
......
......@@ -6,15 +6,13 @@ routeEnhancers:
plugin: Pi1
routes:
-
routePath: '/{uid}'
routePath: '/{slug}'
_controller: 'Front::detail'
_arguments:
uid: 'uid'
slug: 'uid'
defaultController: 'Front::detail'
requirements:
uid: \d+
aspects:
uid:
slug:
type: PersistedAliasMapper
tableName: tx_lunames_domain_model_person
routeFieldName: uid
tableName: 'tx_lunames_domain_model_person'
routeFieldName: 'slug'
......@@ -333,19 +333,11 @@ return [
'label' => $ll.'tx_lunames_domain_model_family_status.label',
'config' => [
'type' => 'select',
'minitems' => 0,
'maxitems' => 1,
'renderType' => 'selectSingle',
'foreign_table' => 'tx_lunames_domain_model_family_status',
'foreign_table_where' => 'ORDER BY tx_lunames_domain_model_family_status.title ASC',
'items' => [['', '',]],
'fieldControl' => [
'addRecord' => [
'disabled' => false,
'options' => [
'title' => $ll.'tx_lunames_domain_model_family_status.add',
],
],
],
'items' => [['', 0]],
'default' => 0,
],
],
'spouse' => [
......@@ -397,9 +389,26 @@ return [
],
],
],
'slug' => [
'label' => $ll.'tx_lunames_domain_model_person.slug',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['uid', 'family_name', 'given_name'],
'fieldSeparator' => '-',
'prefixParentPageSlug' => false,
'replacements' => [
'/' => '',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'default' => ''
],
],
],
'types' => [
'0' => ['showitem' => 'photo, --palette--;;names, --palette--;;family_status, --palette--;;parents, --palette--;;birth, --palette--;;death, --palette--;;locations, occupation, --palette--;;fate, source_codes'],
'0' => ['showitem' => 'photo, --palette--;;names, --palette--;;family_status, --palette--;;parents, --palette--;;birth, --palette--;;death, --palette--;;locations, occupation, --palette--;;fate, source_codes, slug'],
],
'palettes' => [
'names' => [
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2020-10-13T14:21:58Z">
<file source-language="en" datatype="plaintext" original="messages" date="2020-12-03T10:35:07Z">
<header>
<generator>LFEditor</generator>
</header>
<body>
<trans-unit id="found.entries.0" approved="yes">
<source><![CDATA[Found %s entries]]></source>
</trans-unit>
<trans-unit id="found.entries.1" approved="yes">
<source><![CDATA[Found %s entries]]></source>
</trans-unit>
<trans-unit id="administration.noRecordsFound">
<source><![CDATA[No records found on this page.]]></source>
</trans-unit>
......@@ -23,6 +17,12 @@
<trans-unit id="extension.title">
<source><![CDATA[Names]]></source>
</trans-unit>
<trans-unit id="found.entries.0">
<source><![CDATA[Found %s entries]]></source>
</trans-unit>
<trans-unit id="found.entries.1">
<source><![CDATA[Found %s entries]]></source>
</trans-unit>
<trans-unit id="module.createNewRecord">
<source><![CDATA[Add new]]></source>
</trans-unit>
......@@ -56,6 +56,9 @@
<trans-unit id="tx_lunames_domain_model_person.august">
<source><![CDATA[August]]></source>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.comments">
<source><![CDATA[Comments]]></source>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.day_of_birth">
<source><![CDATA[Day of birth]]></source>
</trans-unit>
......@@ -152,6 +155,9 @@
<trans-unit id="tx_lunames_domain_model_person.september">
<source><![CDATA[September]]></source>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.slug">
<source><![CDATA[URL path segment]]></source>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.source_codes">
<source><![CDATA[Sources]]></source>
</trans-unit>
......@@ -170,9 +176,6 @@
<trans-unit id="tx_lunames_domain_model_source.label">
<source><![CDATA[Source]]></source>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.comments">
<source><![CDATA[Comments]]></source>
</trans-unit>
</body>
</file>
</xliff>
</xliff>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="lv" datatype="plaintext" original="messages" date="2020-11-10T08:31:49Z">
<file source-language="en" target-language="lv" datatype="plaintext" original="messages" date="2020-12-03T10:35:07Z">
<header>
<generator>LFEditor</generator>
</header>
......@@ -21,6 +21,14 @@
<source><![CDATA[Names]]></source>
<target><![CDATA[Names]]></target>
</trans-unit>
<trans-unit id="found.entries.0" approved="yes">
<source><![CDATA[Found %s entries]]></source>
<target><![CDATA[Atrasti %s ieraksti]]></target>
</trans-unit>
<trans-unit id="found.entries.1" approved="yes">
<source><![CDATA[Found %s entries]]></source>
<target><![CDATA[Atrasts %s ieraksts]]></target>
</trans-unit>
<trans-unit id="module.createNewRecord" approved="yes">
<source><![CDATA[Add new]]></source>
<target><![CDATA[Pievienot jaunu]]></target>
......@@ -81,6 +89,10 @@
<source><![CDATA[December]]></source>
<target><![CDATA[Decembris]]></target>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.fate" approved="yes">
<source><![CDATA[Fate in 1941-1945]]></source>
<target><![CDATA[Liktenis no 1941 līdz 1945]]></target>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.father" approved="yes">
<source><![CDATA[Father]]></source>
<target><![CDATA[Tēvs]]></target>
......@@ -193,6 +205,10 @@
<source><![CDATA[September]]></source>
<target><![CDATA[Septembris]]></target>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.slug" approved="yes">
<source><![CDATA[URL path segment]]></source>
<target><![CDATA[URL segments]]></target>
</trans-unit>
<trans-unit id="tx_lunames_domain_model_person.source_codes" approved="yes">
<source><![CDATA[Sources]]></source>
<target><![CDATA[Avoti]]></target>
......
{
"name": "luitd/lu-names",
"version": "1.0.1",
"version": "1.0.3",
"description": "Jews in Latvia names database extension for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -9,7 +9,7 @@ $EM_CONF[$_EXTKEY] = [
'author_email' => 'lauris.karklis@lu.lv, dainis.abols@lu.lv',
'state' => 'stable',
'clearCacheOnLoad' => true,
'version' => '1.0.1',
'version' => '1.0.3',
'constraints' => [
'depends' => [
'typo3' => '9.5.0-9.9.99',
......
......@@ -35,6 +35,7 @@ CREATE TABLE tx_lunames_domain_model_person
`fate` text DEFAULT '' NOT NULL,
`comments` text DEFAULT '' NOT NULL,
`source_codes` varchar(255) DEFAULT '' NOT NULL,
`slug` varchar(2048),
PRIMARY KEY (uid),
KEY parent (pid)
......
......@@ -4,7 +4,7 @@ Jews in Latvia names database extension for TYPO3TYPO3 Extension for Regulations
## Version
1.0.1
1.0.3
## Dependecies
......
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