Skip to content

Commit

Permalink
Add database engine check
Browse files Browse the repository at this point in the history
  • Loading branch information
tbradsha committed Jan 5, 2024
1 parent 217022c commit 7b8378c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
2 changes: 1 addition & 1 deletion projects/plugins/crm/admin/system/system-status.page.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function zeroBSCRM_render_systemstatus_page() {
'corever' => 'CRM Core Version',
'dbver' => 'Database Version',
'dalver' => 'DAL Version',
'mysql' => 'MySQL Version',
'dbserver' => 'Database Server (version)',
'innodb' => 'InnoDB Storage Engine',
'sqlrights' => 'SQL Permissions',
'locale' => 'Locale',
Expand Down
34 changes: 26 additions & 8 deletions projects/plugins/crm/includes/ZeroBSCRM.Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,19 +801,37 @@ public function is_database_installed() {
* Retrieves MySQL/MariaDB/Percona database server info
*/
public function get_database_server_info() {

if ( empty( $this->database_server_info ) ) {
global $wpdb;
$raw_version = $wpdb->get_var( 'SELECT VERSION()' );
$version = preg_replace( '/[^0-9.].*/', '', $raw_version );
$is_mariadb = ! ( stripos( $raw_version, 'mariadb' ) === false );

// Adapted from proposed SQLite integration for core
// https://github.com/WordPress/sqlite-database-integration/blob/4a687709bb16a569a7d1ecabfcce433c0e471de8/health-check.php
if ( defined( 'DB_ENGINE' ) && DB_ENGINE === 'sqlite' ) {
$db_engine = DB_ENGINE;
$db_engine_label = 'SQLite';
$raw_version = class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null;
$version = $raw_version;
} else {
global $wpdb;
$raw_version = $wpdb->get_var( 'SELECT VERSION()' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$version = preg_replace( '/[^0-9.].*/', '', $raw_version );
if ( stripos( $raw_version, 'mariadb' ) !== false ) {
$db_engine = 'mariadb';
$db_engine_label = 'MariaDB';
} else {
$db_engine = 'mysql';
$db_engine_label = 'MySQL';
}
}

$database_server_info = array(
'raw_version' => $raw_version,
'version' => $version,
'is_mariadb' => $is_mariadb,
'raw_version' => $raw_version,
'version' => $version,
'db_engine' => $db_engine,
'db_engine_label' => $db_engine_label,
);
$this->database_server_info = $database_server_info;
}

return $this->database_server_info;
}

Expand Down
30 changes: 23 additions & 7 deletions projects/plugins/crm/includes/ZeroBSCRM.Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1016,24 +1016,40 @@ function zeroBSCRM_DB_canInnoDB(){

}

function zeroBSCRM_database_getVersion(){
/**
* Get info about the database engine.
*
* @param boolean $pretty Retrieve a user-friendly label instead of a slug.
*
* @return string
*/
function jpcrm_database_engine( $pretty = false ) {
global $zbs;
return $zbs->database_server_info['raw_version'];
if ( $pretty ) {
return $zbs->database_server_info['db_engine_label'];
}
return $zbs->database_server_info['db_engine'];
}

// determine if current database server is MariaDB
function jpcrm_database_server_is_mariadb() {
/**
* Get the database version.
*
* @return string
*/
function zeroBSCRM_database_getVersion() {
global $zbs;
return $zbs->database_server_info['is_mariadb'];
return $zbs->database_server_info['raw_version'];
}

function jpcrm_database_server_has_ability( $ability_name ) {
global $zbs;
$db_server_version = zeroBSCRM_database_getVersion();
$is_mariadb = jpcrm_database_server_is_mariadb();
$db_engine = $zbs->database_server_info['db_engine'];

if ( $ability_name === 'fulltext_index' ) {
if ( $is_mariadb ) {
if ( $db_engine === 'sqlite' ) {
return false;
} elseif ( $db_engine === 'mariadb' ) {
// first stable 10.x release
return version_compare( $db_server_version, '10.0.10', '>=' );
} else {
Expand Down
21 changes: 12 additions & 9 deletions projects/plugins/crm/includes/ZeroBSCRM.SystemChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function zeroBSCRM_checkSystemFeat( $key = '', $with_info = false ) {
'sqlrights',
'devmode',
'permalinks',
'mysql',
'dbserver',
'innodb',
'fontinstalled',
'encryptionmethod',
Expand Down Expand Up @@ -309,15 +309,18 @@ function zeroBSCRM_checkSystemFeat_sqlrights($withInfo=false){
}
}

// what mysql we running
function zeroBSCRM_checkSystemFeat_mysql($withInfo=false){

if (!$withInfo)
return zeroBSCRM_database_getVersion();
else
return array(1, zeroBSCRM_database_getVersion());

/**
* Get info about the database server engine and version.
*
* @param boolean $with_info Provides extra info.
*/
function zeroBSCRM_checkSystemFeat_dbserver( $with_info = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! $with_info ) {
return zeroBSCRM_database_getVersion();
} else {
return array( 1, jpcrm_database_engine( true ) . ' (' . zeroBSCRM_database_getVersion() . ')' );
}
}

// got InnoDB?
function zeroBSCRM_checkSystemFeat_innodb($withInfo=false){
Expand Down

0 comments on commit 7b8378c

Please sign in to comment.