Skip to content

Commit

Permalink
Merge branch 'master' into issue836-guess-vocab-default
Browse files Browse the repository at this point in the history
  • Loading branch information
osma authored Apr 23, 2019
2 parents 43b3e62 + 508c6d9 commit 41a73a8
Show file tree
Hide file tree
Showing 116 changed files with 329 additions and 13 deletions.
9 changes: 7 additions & 2 deletions controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Controller
{
/**
* The controller has to know the model to access the data stored there.
* @param $model contains the Model object.
* @var Model $model contains the Model object.
*/
public $model;

Expand Down Expand Up @@ -151,7 +151,12 @@ protected function sendNotModifiedHeader($modifiedDate): bool
*/
protected function getIfModifiedSince()
{
return isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ? strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) : null;
$ifModifiedSince = null;
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
// example value set by a browser: "2019-04-13 08:28:23"
$ifModifiedSince = DateTime::createFromFormat("Y-m-d H:i:s", $_SERVER["HTTP_IF_MODIFIED_SINCE"]);
}
return $ifModifiedSince;
}

/**
Expand Down
92 changes: 92 additions & 0 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
class WebController extends Controller
{
/**
* How long to store retrieved disk configuration for HTTP 304 header
* from git information.
*/
const GIT_MODIFIED_CONFIG_TTL = 600; // 10 minutes
/**
* Provides access to the templating engine.
* @property object $twig the twig templating engine.
Expand Down Expand Up @@ -260,6 +265,30 @@ public function invokeVocabularyConcept(Request $request)
* @return DateTime|null
*/
protected function getModifiedDate(Concept $concept, Vocabulary $vocab)
{
$modifiedDate = null;

$conceptModifiedDate = $this->getConceptModifiedDate($concept, $vocab);
$gitModifiedDate = $this->getGitModifiedDate();
$configModifiedDate = $this->getConfigModifiedDate();

// max with an empty list raises an error and returns bool
if ($conceptModifiedDate || $gitModifiedDate || $configModifiedDate) {
$modifiedDate = max($conceptModifiedDate, $gitModifiedDate, $configModifiedDate);
}
return $modifiedDate;
}

/**
* Get the concept modified date. Returns the concept modified date if available. Otherwise,
* reverts to the modified date of the default concept scheme if available. Lastly, if it could
* not get the modified date from the concept nor from the concept scheme, it returns null.
*
* @param Concept $concept concept used to retrieve modified date
* @param Vocabulary $vocab vocabulary used to retrieve modified date
* @return DateTime|null|string
*/
protected function getConceptModifiedDate(Concept $concept, Vocabulary $vocab)
{
$modifiedDate = $concept->getModifiedDate();
if (!$modifiedDate) {
Expand All @@ -274,9 +303,72 @@ protected function getModifiedDate(Concept $concept, Vocabulary $vocab)
}
}
}

return $modifiedDate;
}

/**
* Return the datetime of the latest commit, or null if git is not available or if the command failed
* to execute.
*
* @see https://stackoverflow.com/a/33986403
* @return DateTime|null
*/
protected function getGitModifiedDate()
{
$commitDate = null;
$cache = $this->model->getConfig()->getCache();
$cacheKey = "git:modified_date";
$gitCommand = 'git log -1 --date=iso --pretty=format:%cd';
if ($cache->isAvailable()) {
$commitDate = $cache->fetch($cacheKey);
if (!$commitDate) {
$commitDate = $this->executeGitModifiedDateCommand($gitCommand);
if ($commitDate) {
$cache->store($cacheKey, $commitDate, static::GIT_MODIFIED_CONFIG_TTL);
}
}
} else {
$commitDate = $this->executeGitModifiedDateCommand($gitCommand);
}
return $commitDate;
}

/**
* Execute the git command and return a parsed date time, or null if the command failed.
*
* @param string $gitCommand git command line that returns a formatted date time
* @return DateTime|null
*/
protected function executeGitModifiedDateCommand($gitCommand)
{
$commitDate = null;
$commandOutput = @exec($gitCommand);
if ($commandOutput) {
$commitDate = new \DateTime(trim($commandOutput));
$commitDate->setTimezone(new \DateTimeZone('UTC'));
}
return $commitDate;
}

/**
* Return the datetime of the modified time of the config file. This value is read in the GlobalConfig
* for every request, so we simply access that value and if not null, we will return a datetime. Otherwise,
* we return a null value.
*
* @see http://php.net/manual/en/function.filemtime.php
* @return DateTime|null
*/
protected function getConfigModifiedDate()
{
$dateTime = null;
$configModifiedTime = $this->model->getConfig()->getConfigModifiedTime();
if (!is_null($configModifiedTime)) {
$dateTime = (new DateTime())->setTimestamp($configModifiedTime);
}
return $dateTime;
}

/**
* Invokes the feedback page with information of the users current vocabulary.
*/
Expand Down
1 change: 1 addition & 0 deletions model/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function store($key, $value, $ttl=3600) {
if (function_exists('apcu_store')) {
return apcu_store($key, $value, $ttl);
}
return false;
}

public function isAvailable() {
Expand Down
3 changes: 1 addition & 2 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function getProperties()
// checking if the property value is not in the current vocabulary
$exvoc = $this->model->guessVocabularyFromURI($val->getUri(), $this->vocab->getId());
if ($exvoc && $exvoc->getId() !== $this->vocab->getId()) {
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $this->resource, $prop, $this->clang), $this->clang);
continue;
}
$ret[$prop]->addValue(new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
Expand Down Expand Up @@ -682,7 +682,6 @@ public function getDate()
{
$ret = '';
$created = '';
$modified = '';
try {
// finding the created properties
if ($this->resource->get('dc:created')) {
Expand Down
2 changes: 1 addition & 1 deletion model/ConceptMappingPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function asJskos($queryExVocabs = true)
$ret['to']['memberSet'][0]['notation'] = (string) $notation;
}

$label = $this->getLabel($queryExVocabs);
$label = $this->getLabel(null, $queryExVocabs);
if (isset($label)) {
if (is_string($label)) {
list($labelLang, $labelValue) = ['-', $label];
Expand Down
1 change: 1 addition & 0 deletions model/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DataObject
* Initializes the DataObject
* @param Model $model
* @param EasyRdf\Resource $resource
* @throws Exception
*/
public function __construct($model, $resource)
{
Expand Down
21 changes: 19 additions & 2 deletions model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class GlobalConfig extends BaseConfig {
private $namespaces;
/** EasyRdf\Graph graph */
private $graph;
/**
* @var int the time the config file was last modified
*/
private $configModifiedTime = null;

public function __construct($config_name='/../config.ttl')
{
Expand All @@ -44,6 +48,14 @@ public function getCache()
return $this->cache;
}

/**
* @return int the time the config file was last modified
*/
public function getConfigModifiedTime()
{
return $this->configModifiedTime;
}

/**
* Initialize configuration, reading the configuration file from the disk,
* and creating the graph and resources objects. Uses a cache if available,
Expand All @@ -52,10 +64,15 @@ public function getCache()
private function initializeConfig()
{
try {
// retrieve last modified time for config file (filemtime returns int|bool!)
$configModifiedTime = filemtime($this->filePath);
if (!is_bool($configModifiedTime)) {
$this->configModifiedTime = $configModifiedTime;
}
// use APC user cache to store parsed config.ttl configuration
if ($this->cache->isAvailable()) {
if ($this->cache->isAvailable() && !is_null($this->configModifiedTime)) {
// @codeCoverageIgnoreStart
$key = realpath($this->filePath) . ", " . filemtime($this->filePath);
$key = realpath($this->filePath) . ", " . $this->configModifiedTime;
$nskey = "namespaces of " . $key;
$this->graph = $this->cache->fetch($key);
$this->namespaces = $this->cache->fetch($nskey);
Expand Down
1 change: 1 addition & 0 deletions model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public function getRDF($vocid, $uri, $format)
if (!$result->isEmpty()) {
return $serialiser->serialise($result, $retform);
}
return "";
}

/**
Expand Down
6 changes: 6 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class VocabularyConfig extends BaseConfig
{
private $plugins;
private $languageOrderCache = array();

public function __construct($resource, $globalPlugins=array())
{
Expand Down Expand Up @@ -433,6 +434,9 @@ public function getTypes($lang = null)
*/
public function getLanguageOrder($clang)
{
if (array_key_exists($clang, $this->languageOrderCache)) {
return $this->languageOrderCache[$clang];
}
$ret = array($clang);
$fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array();
foreach ($fallbacks as $lang) {
Expand All @@ -448,6 +452,8 @@ public function getLanguageOrder($clang)
$ret[] = $lang;
}
}
// store in cache so this doesn't have to be computed again
$this->languageOrderCache[$clang] = $ret;
return $ret;
}

Expand Down
Binary file modified resource/fonts/eot/FiraMono-Bold.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraMono-Medium.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraMono-Regular.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-Bold.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-BoldItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Book.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-BookItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Eight.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-EightItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-ExtraBold.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-ExtraBoldItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-ExtraLight.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-ExtraLightItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Four.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-FourItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Hair.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-HairItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Heavy.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-HeavyItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Italic.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-Light.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-LightItalic.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-Medium.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-MediumItalic.eot
Binary file not shown.
Binary file modified resource/fonts/eot/FiraSans-Regular.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-SemiBold.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-SemiBoldItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Thin.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-ThinItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Two.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-TwoItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-Ultra.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-UltraItalic.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-UltraLight.eot
Binary file not shown.
Binary file added resource/fonts/eot/FiraSans-UltraLightItalic.eot
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraMono-Bold.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraMono-Medium.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraMono-Regular.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-Bold.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-BoldItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Book.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-BookItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Eight.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-EightItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-ExtraBold.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-ExtraLight.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-ExtraLightItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Four.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-FourItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Hair.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-HairItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Heavy.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-HeavyItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Italic.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-Light.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-LightItalic.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-Medium.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-MediumItalic.ttf
Binary file not shown.
Binary file modified resource/fonts/ttf/FiraSans-Regular.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-SemiBold.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-SemiBoldItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Thin.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-ThinItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Two.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-TwoItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-Ultra.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-UltraItalic.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-UltraLight.ttf
Binary file not shown.
Binary file added resource/fonts/ttf/FiraSans-UltraLightItalic.ttf
Binary file not shown.
Binary file modified resource/fonts/woff/FiraMono-Bold.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraMono-Medium.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraMono-Regular.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-Bold.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-BoldItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Book.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-BookItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Eight.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-EightItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-ExtraBold.woff
Binary file not shown.
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-ExtraLight.woff
Binary file not shown.
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Four.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-FourItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Hair.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-HairItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Heavy.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-HeavyItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Italic.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-Light.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-LightItalic.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-Medium.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-MediumItalic.woff
Binary file not shown.
Binary file modified resource/fonts/woff/FiraSans-Regular.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-SemiBold.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-SemiBoldItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Thin.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-ThinItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Two.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-TwoItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-Ultra.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-UltraItalic.woff
Binary file not shown.
Binary file added resource/fonts/woff/FiraSans-UltraLight.woff
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions resource/js/docready.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ $(function() { // DOCUMENT READY
$('.clear-search').addClass('clear-search-dark');
}
});

// monkey-patching TypeAhead's Dropdown object for: https://github.com/NatLibFi/Skosmos/issues/773
// Updating typeahead.js to 0.11 requires a few changes that are not really complicated.
// However, our dropdown style is broken, and it appears hard to be fixed. typeahead.js
// Also does not appear to be maintained, so this temporary fix will prevent
// accidental selection of values. TODO: we must fix this in a future release, possibly
// using another library.
var typeaheadInstance = $typeahead.data("ttTypeahead");
typeaheadInstance.dropdown.$menu.off("mouseenter.tt", ".tt-suggestion");
typeaheadInstance.dropdown.$menu.off("mouseleave.tt", ".tt-suggestion");
}

// storing the search input before autocompletion changes it
Expand Down
Loading

0 comments on commit 41a73a8

Please sign in to comment.