Skip to content

Commit

Permalink
Sync Providence changes
Browse files Browse the repository at this point in the history
  • Loading branch information
collectiveaccess committed Dec 23, 2024
1 parent aee4f81 commit f612d19
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/lib/Attributes/Values/TextAttributeValue.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
/** ---------------------------------------------------------------------
* app/lib/Attributes/Values/TextAttributeValue.php :
* ----------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions app/lib/BaseFindController.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public function Index($pa_options=null) {
$vs_label_display_field = $t_label->getDisplayField();
foreach($display_list as $i => $va_display_item) {
$tmp = explode('.', $va_display_item['bundle_name']);

if(!is_array($va_display_item['settings'])) { $va_display_item['settings'] = []; }

if(!isset($tmp[1])){
$tmp[1] = null;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2901,7 +2901,7 @@ public function insert ($pa_options=null) {
* force = if set field values are not verified prior to performing the update
* dontLogChange = don't log change in change log. [Default is false]
* dontUpdateHistoryCurrentValueTracking = Skip updating current value tracking caches. Used internally when deleting rows. [Default is false]
* dontDoSearchIndexing = if set to true then no search indexing on the inserted record is performed. [Default is false]
* dontDoSearchIndexing = if set to true then no search indexing on the updated record is performed. [Default is false]
* @return bool success state
*/
public function update($pa_options=null) {
Expand Down
10 changes: 10 additions & 0 deletions app/lib/BatchProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ public static function saveBatchEditorForm(RequestHTTP $po_request, RecordSelect
'label' => $t_subject->getLabelForDisplay(),
'status' => 'SUCCESS'
);

$opo_app_plugin_manager = new ApplicationPluginManager() ;
$opo_app_plugin_manager->hookSaveItem(
array(
'id' => $vn_row_id,
'table_num' => $t_subject->tableNum(),
'table_name' => $t_subject->tableName(),
'instance' => $t_subject
)
);
}

if (isset($pa_options['progressCallback']) && ($ps_callback = $pa_options['progressCallback'])) {
Expand Down
25 changes: 15 additions & 10 deletions app/lib/ConfigurationCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ public static function init() {
* in index.php and that any errors set here cause the application
* to die and display a nasty configuration error screen.
*/
public static function performQuick($options=null) {
public static function performQuick(?array $options=null) : bool {
self::init();
/* execute checks */
$vo_reflection = new ReflectionClass("ConfigurationCheck");
$va_methods = $vo_reflection->getMethods();
foreach($va_methods as $vo_method){
if(strpos($vo_method->name,"QuickCheck")!==false){
if (caGetOption('skipPathChecks', $options, false) && in_array($vo_method->name, ['caUrlRootQuickCheck', 'caBaseDirQuickCheck'])) { continue; }
if (!$vo_method->invoke(null, "ConfigurationCheck")) {
return;
if (!$vo_method->invoke(null, $options)) {
return false;
}
}
}
return true;
}
# -------------------------------------------------------
/**
Expand All @@ -81,9 +82,9 @@ public static function performQuick($options=null) {
* errors set here are "non-lethal", i.e. the application still works
* although certain features may not function properly.
*/
public static function performExpensive() {
public static function performExpensive(?array $options=null) : bool {
self::init();
self::$opa_error_messages = array();
self::$opa_error_messages = [];
self::$opo_db = new Db();
self::$opo_config = ConfigurationCheck::$opo_db->getConfig();

Expand All @@ -92,11 +93,13 @@ public static function performExpensive() {
$va_methods = $vo_reflection->getMethods();
foreach($va_methods as $vo_method){
if(strpos($vo_method->name,"ExpensiveCheck")!==false){
if (!$vo_method->invoke(null, "ConfigurationCheck")) { // true means keep on doing checks; false means stop performing checks
return;
if (!$vo_method->invoke(null, $options)) { // true means keep on doing checks; false means stop performing checks
return false;
}
}
}

return true;
}
# -------------------------------------------------------
/**
Expand All @@ -113,6 +116,7 @@ public static function performInstall() {
self::permissionInstallCheck();
self::DBLoginQuickCheck();
self::tmpDirQuickCheck();
self::htmlPurifierDirQuickCheck();
}
# -------------------------------------------------------
private static function addError($ps_error) {
Expand Down Expand Up @@ -243,10 +247,10 @@ public static function DBTableQuickCheck() {
/**
* Is the DB schema up-to-date?
*/
public static function DBOutOfDateQuickCheck() {
public static function DBOutOfDateQuickCheck(?array $options=null) {
if (!in_array('ca_schema_updates', self::$opo_db->getTables())) {
self::addError(_t("Your database is extremely out-of-date. Please install all database migrations starting with migration #1 or contact [email protected] for assistance."));
} else if (($vn_schema_revision = self::getSchemaVersion()) < __CollectiveAccess_Schema_Rev__) {
} else if (!caGetOption('forMigration', $options, false) && ($vn_schema_revision = self::getSchemaVersion()) < __CollectiveAccess_Schema_Rev__) {
if($vn_schema_revision <= 158) {
self::addError(_t("You appear to be upgrading a CollectiveAccess 1.7.x system. Upgrading is a multi-step process. Learn more about it at <a href='https://github.com/collectiveaccess/providence/tree/master?tab=readme-ov-file#updating-from-providence-version-17-or-later'>here</a>.</div>"));
} elseif (defined('__CA_ALLOW_AUTOMATIC_UPDATE_OF_DATABASE__') && __CA_ALLOW_AUTOMATIC_UPDATE_OF_DATABASE__) {
Expand Down Expand Up @@ -371,7 +375,8 @@ public static function caUrlRootQuickCheck() {
/**
* I suspect that the application would die before we even reach this check if the base dir is messed up?
*/
public static function caBaseDirQuickCheck() {
public static function caBaseDirQuickCheck(?array $options=null) {
if(caGetOption('forMigration', $options, false)) { return true; }
$possible_bases = self::_baseGuesses();

if (caGetOSFamily() === OS_WIN32) { // Windows paths are case insensitive
Expand Down
3 changes: 2 additions & 1 deletion app/lib/Controller/Request/RequestHTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ public function doAuthentication($pa_options) {
}
return false;
} else {
$msg = "Successful login for '".$pa_options["user_name"]."'; IP=".$_SERVER["REMOTE_ADDR"]."; user agent=".RequestHTTP::ip();
$user_name = ($this->user && $this->user->getUserID()) ? $this->user->get('user_name') : ($pa_options["user_name"] ?? null);
$msg = "Successful login for '{$user_name}'; IP=".RequestHTTP::ip()."; user agent=".($_SERVER['HTTP_USER_AGENT'] ?? null);
caLogEvent('LOGIN', $msg, 'Auth'); // write logins to text log

require_once(__CA_LIB_DIR__."/Logging/Eventlog.php");
Expand Down
4 changes: 3 additions & 1 deletion app/lib/Parsers/ExpressionParser/ExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2015-2023 Whirl-i-Gig
* Copyright 2015-2024 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
Expand Down Expand Up @@ -96,6 +96,8 @@ protected function initializeFunctions() {
'ageyears' => xcallable('caCalculateAgeInYears'),
'agedays' => xcallable('caCalculateAgeInDays'),
'avgdays' => xcallable('caCalculateDateRangeAvgInDays'),
'earliestDate' => xcallable('caGetEarliestDate'),
'latestDate' => xcallable('caGetLatestDate'),
'average' => xcallable($average),
'avg' => xcallable($average),
'sum' => xcallable(function () { return array_sum(func_get_args()); }),
Expand Down
9 changes: 9 additions & 0 deletions app/lib/Plugins/SearchEngine/SqlSearch2.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ public function init() {
}
}
# -------------------------------------------------------
/**
* Clear internal engine caches
*/
public function clearCaches() : void {
WLPlugSearchEngineSqlSearch2::$fieldnum_cache = [];
WLPlugSearchEngineSqlSearch2::$metadata_elements = [];
WLPlugSearchEngineSqlSearch2::$word_cache = [];
}
# -------------------------------------------------------
/**
* Set database connection
*
Expand Down
40 changes: 25 additions & 15 deletions app/lib/Search/SearchIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public function __destruct() {
}
}
# -------------------------------------------------------
/**
* Clear internal indexer caches
*/
public function clearCaches() : void {
if($this->opo_engine && method_exists($this->opo_engine, 'clearCaches')) {
$this->opo_engine->clearCaches();
}
}
# -------------------------------------------------------
/**
*
*/
Expand Down Expand Up @@ -782,32 +791,33 @@ public function indexRow($pn_subject_table_num, $pn_subject_row_id, $pa_field_da
if (((isset($va_data['INDEX_AS_IDNO']) && $va_data['INDEX_AS_IDNO']) || in_array('INDEX_AS_IDNO', $va_data, true)) && method_exists($t_subject, "getIDNoPlugInInstance") && ($o_idno = $t_subject->getIDNoPlugInInstance())) {
if ((is_array($va_data['IDNO_DELIMITERS'] ?? null) && count($va_data['IDNO_DELIMITERS'])) || strlen($va_data['IDNO_DELIMITERS'] ?? null)) {
if (!is_array($va_data['IDNO_DELIMITERS'])) { $va_data['IDNO_DELIMITERS'] = [$va_data['IDNO_DELIMITERS']]; }
$va_values = array_map(function($v) { return trim($v); }, preg_split('!('.join('|', $va_data['IDNO_DELIMITERS']).')!', $pa_field_data[$vs_field]));
$values = array_map(function($v) { return trim($v); }, preg_split('!('.join('|', $va_data['IDNO_DELIMITERS']).')!', $pa_field_data[$vs_field]));
} else {
$va_values = $o_idno->getIndexValues($pa_field_data[$vs_field], $va_data);
$values = $o_idno->getIndexValues($pa_field_data[$vs_field], $va_data);
}
$vn_fld_num = $t_subject->fieldNum($vs_field);

foreach($values as $v) {
$this->opo_engine->indexField($pn_subject_table_num, "I{$vn_fld_num}", $pn_subject_row_id, [$v], array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
}
$fld_init = true;
$this->_genIndexInheritance($t_subject, null, "I{$vn_fld_num}", $pn_subject_row_id, $pn_subject_row_id, $va_values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
$this->_genIndexInheritance($t_subject, null, "I{$vn_fld_num}", $pn_subject_row_id, $pn_subject_row_id, $values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
}

// specialized mimetype processing
if (((isset($va_data['INDEX_AS_MIMETYPE']) && $va_data['INDEX_AS_MIMETYPE']) || in_array('INDEX_AS_MIMETYPE', $va_data, true))) {
$va_values = [];
$values = [];
if ($vs_typename = Media::getTypenameForMimetype($pa_field_data[$vs_field])) {
$va_values[] = $vs_typename;
$values[] = $vs_typename;
}
$vn_fld_num = $t_subject->fieldNum($vs_field);

// Index mimetype as-is
$this->opo_engine->indexField($pn_subject_table_num, "I{$vn_fld_num}", $pn_subject_row_id, [$pa_field_data[$vs_field]], array_merge($va_data, ['DONT_TOKENIZE' => true, 'dontRemoveExistingIndexing' => $fld_init]));
$fld_init = true;

$this->opo_engine->indexField($pn_subject_table_num, "I{$vn_fld_num}", $pn_subject_row_id, $va_values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
$this->_genIndexInheritance($t_subject, null, "I{$vn_fld_num}", $pn_subject_row_id, $pn_subject_row_id, $va_values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
$this->opo_engine->indexField($pn_subject_table_num, "I{$vn_fld_num}", $pn_subject_row_id, $values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
$this->_genIndexInheritance($t_subject, null, "I{$vn_fld_num}", $pn_subject_row_id, $pn_subject_row_id, $values, array_merge($va_data, ['dontRemoveExistingIndexing' => $fld_init]));
continue;
}

Expand Down Expand Up @@ -1143,25 +1153,25 @@ public function indexRow($pn_subject_table_num, $pn_subject_row_id, $pa_field_da

if (strlen($va_rel_field_info['IDNO_DELIMITERS']) || (is_array($va_rel_field_info['IDNO_DELIMITERS']) && count($va_rel_field_info['IDNO_DELIMITERS']))) {
if (!is_array($va_rel_field_info['IDNO_DELIMITERS'])) { $va_rel_field_info['IDNO_DELIMITERS'] = [$va_rel_field_info['IDNO_DELIMITERS']]; }
$va_values = array_map(function($v) { return trim($v); }, preg_split('!('.join('|', $va_rel_field_info['IDNO_DELIMITERS']).')!', $vs_fld_data));
$values = array_map(function($v) { return trim($v); }, preg_split('!('.join('|', $va_rel_field_info['IDNO_DELIMITERS']).')!', $vs_fld_data));
} else {
$va_values = $o_idno->getIndexValues($vs_fld_data, $va_rel_field_info);
$values = $o_idno->getIndexValues($vs_fld_data, $va_rel_field_info);
}
$this->opo_engine->indexField($is_generic ? $pn_subject_table_num : $vn_related_table_num, $field_num, $vn_id = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), $va_values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private)));
$this->_genIndexInheritance($t_subject, $t_rel, $field_num, $pn_subject_row_id, $vn_id, $va_values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private, 'isGeneric' => $is_generic)));
$this->opo_engine->indexField($is_generic ? $pn_subject_table_num : $vn_related_table_num, $field_num, $vn_id = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), $values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private)));
$this->_genIndexInheritance($t_subject, $t_rel, $field_num, $pn_subject_row_id, $vn_id, $values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private, 'isGeneric' => $is_generic)));
}
if (((isset($va_rel_field_info['INDEX_AS_MIMETYPE']) && $va_rel_field_info['INDEX_AS_MIMETYPE']) || in_array('INDEX_AS_MIMETYPE', $va_rel_field_info, true))) {
// specialized mimetype processing
$va_values = [];
$values = [];
if ($vs_typename = Media::getTypenameForMimetype($vs_fld_data)) {
$va_values[] = $vs_typename;
$values[] = $vs_typename;
}
// Index mimetype as-is
$this->opo_engine->indexField($is_generic ? $pn_subject_table_num : $vn_related_table_num, $field_num, $vn_id = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), [$vs_fld_data], array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private, 'DONT_TOKENIZE' => true)));

// Index typename
$this->opo_engine->indexField($is_generic ? $pn_subject_table_num : $vn_related_table_num, $field_num, $vn_id = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), $va_values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private)));
$this->_genIndexInheritance($t_subject, $t_rel, $field_num, $pn_subject_row_id, $vn_id, $va_values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private, 'isGeneric' => $is_generic)));
$this->opo_engine->indexField($is_generic ? $pn_subject_table_num : $vn_related_table_num, $field_num, $vn_id = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), $values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private)));
$this->_genIndexInheritance($t_subject, $t_rel, $field_num, $pn_subject_row_id, $vn_id, $values, array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private, 'isGeneric' => $is_generic)));
} else {
// regular intrinsic
$this->opo_engine->indexField(($is_generic ? $pn_subject_table_num : $vn_related_table_num), $field_num, $vn_rid = $is_generic ? $pn_subject_row_id : $qr_res->get($vs_related_pk), [$vs_fld_data], array_merge($va_rel_field_info, array('relationship_type_id' => $vn_rel_type_id, 'PRIVATE' => $vn_private)));
Expand Down
8 changes: 4 additions & 4 deletions app/lib/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,7 @@ function getMediaInfo($ps_field, $ps_version=null, $ps_key=null, $pa_options=nul
if (!($this->opa_field_media_info[$ps_field] ?? null)) {
$this->opa_field_media_info[$ps_field] = $this->get($ps_field, array("unserialize" => true, 'returnWithStructure' => true));
}
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaInfo($ps_version, $ps_key, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field])]));
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaInfo($ps_version, $ps_key, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field] ?? [])]));
}
# ------------------------------------------------------------------
/**
Expand All @@ -3353,7 +3353,7 @@ function getMediaPath($ps_field, $ps_version, $pa_options=null) {
if (!($this->opa_field_media_info[$ps_field] ?? null)) {
$this->opa_field_media_info[$ps_field] = $this->get($ps_field, array("unserialize" => true, 'returnWithStructure' => true));
}
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaPath($ps_version, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field])]));
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaPath($ps_version, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field] ?? [])]));
}
# ------------------------------------------------------------------
/**
Expand Down Expand Up @@ -3383,7 +3383,7 @@ function getMediaUrl($ps_field, $ps_version, $pa_options=null) {
if (!$this->opa_field_media_info[$ps_field]) {
$this->opa_field_media_info[$ps_field] = $this->get($ps_field, array("unserialize" => true, 'returnWithStructure' => true));
}
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaUrl($ps_version, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field])]));
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaUrl($ps_version, array_merge($pa_options, ['data' => array_shift($this->opa_field_media_info[$ps_field] ?? [])]));
}
# ------------------------------------------------------------------
/**
Expand Down Expand Up @@ -3423,7 +3423,7 @@ function getMediaTag($ps_field, $ps_version, $pa_options=null) {
} else {
$alt_text = null;
}
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaTag($ps_version, array_merge($pa_options, ['alt' => $alt_text, 'data' => reset($this->opa_field_media_info[$ps_field])]));
return $GLOBALS["_DbResult_mediainfocoder"]->getMediaTag($ps_version, array_merge($pa_options, ['alt' => $alt_text, 'data' => reset($this->opa_field_media_info[$ps_field] ?? [])]));
}
# ------------------------------------------------------------------
/**
Expand Down
Loading

0 comments on commit f612d19

Please sign in to comment.