diff --git a/app/lib/Attributes/Values/TextAttributeValue.php b/app/lib/Attributes/Values/TextAttributeValue.php index c511cd19cb..8a03e98777 100644 --- a/app/lib/Attributes/Values/TextAttributeValue.php +++ b/app/lib/Attributes/Values/TextAttributeValue.php @@ -1,4 +1,4 @@ - 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; diff --git a/app/lib/BaseModel.php b/app/lib/BaseModel.php index 31507f8760..59b4dc5a1f 100755 --- a/app/lib/BaseModel.php +++ b/app/lib/BaseModel.php @@ -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) { diff --git a/app/lib/BatchProcessor.php b/app/lib/BatchProcessor.php index 777f21c67d..0470bc5dc1 100644 --- a/app/lib/BatchProcessor.php +++ b/app/lib/BatchProcessor.php @@ -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'])) { diff --git a/app/lib/ConfigurationCheck.php b/app/lib/ConfigurationCheck.php index 4ffdafccfa..20e09dfeb0 100644 --- a/app/lib/ConfigurationCheck.php +++ b/app/lib/ConfigurationCheck.php @@ -60,7 +60,7 @@ 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"); @@ -68,11 +68,12 @@ public static function performQuick($options=null) { 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; } # ------------------------------------------------------- /** @@ -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(); @@ -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; } # ------------------------------------------------------- /** @@ -113,6 +116,7 @@ public static function performInstall() { self::permissionInstallCheck(); self::DBLoginQuickCheck(); self::tmpDirQuickCheck(); + self::htmlPurifierDirQuickCheck(); } # ------------------------------------------------------- private static function addError($ps_error) { @@ -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 support@collectiveaccess.org 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 here.")); } elseif (defined('__CA_ALLOW_AUTOMATIC_UPDATE_OF_DATABASE__') && __CA_ALLOW_AUTOMATIC_UPDATE_OF_DATABASE__) { @@ -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 diff --git a/app/lib/Controller/Request/RequestHTTP.php b/app/lib/Controller/Request/RequestHTTP.php index 21c7a19324..7a07df50c0 100644 --- a/app/lib/Controller/Request/RequestHTTP.php +++ b/app/lib/Controller/Request/RequestHTTP.php @@ -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"); diff --git a/app/lib/Parsers/ExpressionParser/ExpressionVisitor.php b/app/lib/Parsers/ExpressionParser/ExpressionVisitor.php index 23cf8af1fe..8136bc8330 100644 --- a/app/lib/Parsers/ExpressionParser/ExpressionVisitor.php +++ b/app/lib/Parsers/ExpressionParser/ExpressionVisitor.php @@ -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 * @@ -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()); }), diff --git a/app/lib/Plugins/SearchEngine/SqlSearch2.php b/app/lib/Plugins/SearchEngine/SqlSearch2.php index 2420658d8e..baa6a9753d 100644 --- a/app/lib/Plugins/SearchEngine/SqlSearch2.php +++ b/app/lib/Plugins/SearchEngine/SqlSearch2.php @@ -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 * diff --git a/app/lib/Search/SearchIndexer.php b/app/lib/Search/SearchIndexer.php index b487d9c45e..a98bb29497 100644 --- a/app/lib/Search/SearchIndexer.php +++ b/app/lib/Search/SearchIndexer.php @@ -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(); + } + } + # ------------------------------------------------------- /** * */ @@ -782,23 +791,24 @@ 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); @@ -806,8 +816,8 @@ public function indexRow($pn_subject_table_num, $pn_subject_row_id, $pa_field_da $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; } @@ -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))); diff --git a/app/lib/Search/SearchResult.php b/app/lib/Search/SearchResult.php index cee20dbb03..0c3efb140a 100755 --- a/app/lib/Search/SearchResult.php +++ b/app/lib/Search/SearchResult.php @@ -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] ?? [])])); } # ------------------------------------------------------------------ /** @@ -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] ?? [])])); } # ------------------------------------------------------------------ /** @@ -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] ?? [])])); } # ------------------------------------------------------------------ /** @@ -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] ?? [])])); } # ------------------------------------------------------------------ /** diff --git a/app/lib/Utils/CLIUtils/Maintenance.php b/app/lib/Utils/CLIUtils/Maintenance.php index ce6103b275..d03f29024e 100644 --- a/app/lib/Utils/CLIUtils/Maintenance.php +++ b/app/lib/Utils/CLIUtils/Maintenance.php @@ -32,11 +32,11 @@ trait CLIUtilsMaintenance { # ------------------------------------------------------- /** - * Rebuild search indices + * Rebuild sort values */ public static function rebuild_sort_values($po_opts=null) { $o_db = new Db(); - ini_set('memory_limit', '4000m'); + ini_set('memory_limit', '4096m'); $tables = $po_opts ? trim((string)$po_opts->getOption('table')) : null; @@ -62,30 +62,34 @@ public static function rebuild_sort_values($po_opts=null) { $t_label = new $vs_label_table_name; $vs_label_pk = $t_label->primaryKey(); $qr_labels = $o_db->query("SELECT {$vs_label_pk} FROM {$vs_label_table_name}"); + + $table_name_display = $t_label->getProperty('NAME_PLURAL'); print CLIProgressBar::start($qr_labels->numRows(), _t('Processing %1', $t_label->getProperty('NAME_PLURAL'))); while($qr_labels->nextRow()) { $vn_label_pk_val = $qr_labels->get($vs_label_pk); - CLIProgressBar::setMessage(_t("Memory: %1", caGetMemoryUsage())); + CLIProgressBar::setMessage(_t("[Sort: %1][Mem: %2]", $table_name_display, caGetMemoryUsage())); print CLIProgressBar::next(); if ($t_label->load($vn_label_pk_val)) { $t_table->logChanges(false); - $t_label->update(); + $t_label->update(['dontDoSearchIndexing' => true]); } } print CLIProgressBar::finish(); } print CLIProgressBar::start($qr_res->numRows(), _t('Processing %1 identifiers', $t_table->getProperty('NAME_SINGULAR'))); + + $table_name_display = $t_table->getProperty('NAME_PLURAL'); while($qr_res->nextRow()) { $vn_pk_val = $qr_res->get($vs_pk); - CLIProgressBar::setMessage(_t("Memory: %1", caGetMemoryUsage())); + CLIProgressBar::setMessage(_t("[Sort: %1 identifiers][Mem: %2]", $table_name_display, caGetMemoryUsage())); print CLIProgressBar::next(); if ($t_table->load($vn_pk_val)) { $t_table->logChanges(false); - $t_table->update(); + $t_table->update(['dontDoSearchIndexing' => true]); } } print CLIProgressBar::finish(); @@ -1052,18 +1056,25 @@ public static function clear_caches($po_opts=null) { $config = Configuration::load(); $ps_cache = strtolower($po_opts ? (string)$po_opts->getOption('cache') : 'all'); - if (!in_array($ps_cache, array('all', 'app', 'usermedia'))) { $ps_cache = 'all'; } + if (!in_array($ps_cache, ['all', 'app', 'usermedia'])) { $ps_cache = 'all'; } - if (in_array($ps_cache, array('all', 'app'))) { + if (in_array($ps_cache, ['all', 'app'])) { CLIUtils::addMessage(_t('Clearing application caches...')); if (is_writable($config->get('taskqueue_tmp_directory'))) { caRemoveDirectory($config->get('taskqueue_tmp_directory'), false); + mkdir($config->get('purify_serializer_path')); } else { CLIUtils::addError(_t('Skipping clearing of application cache because it is not writable')); } - PersistentCache::flush(); + try { + PersistentCache::flush(); + } catch(Exception $e) { + // noop + } + ExternalCache::flush(); + MemoryCache::flush(); } - if (in_array($ps_cache, array('all', 'usermedia'))) { + if (in_array($ps_cache, ['all', 'usermedia'])) { if (($vs_tmp_directory = $config->get('media_uploader_root_directory')) && (file_exists($vs_tmp_directory))) { if (is_writable($vs_tmp_directory)) { CLIUtils::addMessage(_t('Clearing user media cache in %1...', $vs_tmp_directory)); @@ -2088,9 +2099,12 @@ public static function reload_current_values_for_history_tracking_policies($po_o $t = Datamodel::getInstance($table, true); $qr = $table::find('*', ['returnAs' => 'searchResult']); print CLIProgressBar::start($qr->numHits(), _t('Starting...')); + + $table_name_display = $t->getProperty('NAME_PLURAL'); + while($qr->nextHit()) { if ($t->load($qr->getPrimaryKey())) { - print CLIProgressBar::next(1, _t('Processing %1', $t->getWithTemplate("^{$table}.preferred_labels (^{$table}.idno)"))); + print CLIProgressBar::next(1, _t('[History: %1][Mem: %2] %3', $table_name_display, caGetMemoryUsage(), $t->getWithTemplate("^{$table}.preferred_labels (^{$table}.idno)"))); if ($t->deriveHistoryTrackingCurrentValue()) { $c++; } diff --git a/app/lib/Utils/CLIUtils/Migration.php b/app/lib/Utils/CLIUtils/Migration.php index c97d00f7e5..e3f842bf32 100644 --- a/app/lib/Utils/CLIUtils/Migration.php +++ b/app/lib/Utils/CLIUtils/Migration.php @@ -43,11 +43,17 @@ public static function update_from_1_7($po_opts=null) { return true; } + if(!ConfigurationCheck::performQuick(['forMigration' => true])) { + CLIUtils::addError(_t("Pre-flight checks failed:\n %1", strip_tags(join("\n", array_map(function($v) { return "• {$v}\n"; }, ConfigurationCheck::getErrors()))))); + return false; + } + if(!CLIUtils::confirm(_t("Are you sure you want to update your version 1.7 system (database revision %1)?\nNOTE: you MUST backup your database before applying this update!\n\nType 'y' to proceed or 'n' to cancel, then hit return", $current_revision),['confirmationCode' => 'y', 'color' => 'yellow'])) { return false; } - $num_steps = 8; + + $num_steps = 9; // Clear all caches $c = 1; CLIUtils::addMessage(_t("\n\n------------------------------------------------------------------------------")); @@ -61,6 +67,7 @@ public static function update_from_1_7($po_opts=null) { $db = new Db(); $db->query("TRUNCATE TABLE ca_sql_search_word_index"); $db->query("TRUNCATE TABLE ca_sql_search_words"); + $db->query("TRUNCATE TABLE ca_search_indexing_queue"); $c++; // Apply database updates @@ -93,9 +100,18 @@ public static function update_from_1_7($po_opts=null) { CLIUtils::rebuild_sort_values(); $c++; + // Clear all caches + CLIUtils::addMessage(_t("\n\n------------------------------------------------------------------------------")); + CLIUtils::addMessage(_t("[Step %1/%2] Clearing caches", $c, $num_steps), ['color' => 'yellow']); + CLIUtils::clear_caches(); + $c++; + // Reindex CLIUtils::addMessage(_t("\n\n------------------------------------------------------------------------------")); CLIUtils::addMessage(_t("[Step %1/%2] Rebuilding search index", $c, $num_steps), ['color' => 'yellow']); + $db->query("TRUNCATE TABLE ca_sql_search_word_index"); + $db->query("TRUNCATE TABLE ca_sql_search_words"); + $db->query("TRUNCATE TABLE ca_search_indexing_queue"); CLIUtils::rebuild_search_index(); $c++; diff --git a/app/lib/Utils/CLIUtils/Search.php b/app/lib/Utils/CLIUtils/Search.php index a81ea7058a..ed0b2ab94e 100644 --- a/app/lib/Utils/CLIUtils/Search.php +++ b/app/lib/Utils/CLIUtils/Search.php @@ -41,12 +41,12 @@ public static function rebuild_search_index($po_opts=null) { set_time_limit(24 * 60 * 60 * 7); /* maximum indexing time: 7 days :-) */ $o_si = new SearchIndexer(); - + $o_si->clearCaches(); $va_tables = null; if ($vs_tables = ($po_opts ? (string)$po_opts->getOption('tables') : null)) { $va_tables = preg_split("![;,]+!", $vs_tables); } - $o_si->reindex($va_tables, array('showProgress' => true, 'interactiveProgressDisplay' => true)); + $o_si->reindex($va_tables, ['showProgress' => true, 'interactiveProgressDisplay' => true]); return true; }