Revert "fixes #2166 add feature to send anonymous stats to piwigo.org"

This reverts commit 1106612fc3.

Theses changes were committed on 14.x by mistake
This commit is contained in:
plegall
2024-06-10 21:32:35 +02:00
parent 1106612fc3
commit ec5bce90bf
6 changed files with 119 additions and 512 deletions

View File

@@ -2412,339 +2412,4 @@ SELECT
}
}
/**
* Piwigo *anonymously* sends technical data and general statistics, such as number
* of photos or list of plugins used. It helps piwigo.org to know better how Piwigo
* is used. This way developers can focus on features that matter most.
*
* @since 15
*/
function send_piwigo_infos()
{
global $logger, $conf;
$start_time = get_moment();
if (!$conf['send_piwigo_infos'])
{
return;
}
$do_send = false;
if (isset($conf['send_piwigo_infos_last_notice']))
{
if (strtotime($conf['send_piwigo_infos_last_notice']) < strtotime(conf_get_param('send_piwigo_infos_period', 7*24*60*60).' second ago'))
{
$do_send = true;
}
}
else
{
$do_send = true;
}
if (!$do_send)
{
return;
}
if (!pwg_is_dbconf_writeable())
{
return;
}
$exec_id = substr(sha1(random_bytes(1000)), 0, 8);
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] starts now');
// we only want one send_piwigo_infos to run at once
if (isset($conf['send_piwigo_infos_running']))
{
list($running_exec_id, $running_exec_start_time) = explode('-', $conf['send_piwigo_infos_running']);
if (time() - $running_exec_start_time > 60)
{
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] exec='.$running_exec_id.', timeout stopped by another call to the function');
conf_delete_param('send_piwigo_infos_running');
}
}
$query = '
INSERT IGNORE
INTO '.CONFIG_TABLE.'
SET param="send_piwigo_infos_running"
, value="'.$exec_id.'-'.time().'"
;';
pwg_query($query);
list($send_piwigo_infos_running) = pwg_db_fetch_row(pwg_query('SELECT value FROM '.CONFIG_TABLE.' WHERE param = "send_piwigo_infos_running"'));
list($running_exec_id,) = explode('-', $send_piwigo_infos_running);
if ($running_exec_id != $exec_id)
{
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] skip');
return;
}
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] wins the race and gets the token!');
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
list($db_current_date) = pwg_db_fetch_row(pwg_query('SELECT now();'));
if (!isset($conf['send_piwigo_infos_origin_hash']))
{
conf_update_param('send_piwigo_infos_origin_hash', sha1(random_bytes(1000)), true);
}
$piwigo_infos = array(
'origin_hash' => $conf['send_piwigo_infos_origin_hash'],
'technical' => array(
'php_version' => PHP_VERSION,
'piwigo_version' => PHPWG_VERSION,
'os_version' => PHP_OS,
'db_version' => pwg_get_db_version(),
'php_datetime' => date("Y-m-d H:i:s"),
'db_datetime' => $db_current_date,
'graphics_library' => get_graphics_library(),
),
'general_stats' => get_pwg_general_statitics(),
);
// convert disk_usage from kB to mB
$piwigo_infos['general_stats']['disk_usage'] = intval($piwigo_infos['general_stats']['disk_usage'] / 1024);
$piwigo_infos['general_stats']['installed_on'] = get_installation_date();
// $conf['pem_plugins_category'] = 12;
// $conf['pem_themes_category'] = 10;
$url = PEM_URL . '/api/get_extension_list.php';
if (fetchRemote($url, $result) and $pem_extensions = @unserialize($result))
{
$official_exts = array();
foreach ($pem_extensions as $eid => $ext)
{
if (!empty($ext['archive_root_dir']))
{
@$official_exts[ $ext['idx_category'] ][ $ext['archive_root_dir'] ] = $eid;
}
}
}
else
{
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] fetchRemote on '.$url.' has failed');
}
include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
$plugins = new plugins();
$piwigo_infos['general_stats']['nb_private_plugins'] = 0;
$piwigo_infos['plugins'] = array();
foreach ($plugins->db_plugins_by_id as $plugin)
{
if ('active' == $plugin['state'])
{
$eid = null;
if (isset($plugins->fs_plugins[ $plugin['id'] ]))
{
$uri = $plugins->fs_plugins[ $plugin['id'] ]['uri'];
if (preg_match('/eid=(\d+)/', $uri, $matches))
{
$eid = $matches[1];
}
}
if (empty($eid))
{
// let's search in the data fetched from PEM
$eid = $official_exts[ $conf['pem_plugins_category'] ][ $plugin['id'] ] ?? null;
}
// we must exclude "private extensions". A private extension :
//
// * has no eid
// * OR has un unknown plugin_id among all "Archive root directory" in PEM
if (empty($eid))
{
$piwigo_infos['general_stats']['nb_private_plugins']++;
continue;
}
$piwigo_infos['plugins'][] = (empty($eid) ? 'null' : '#'.$eid).'/'.$plugin['id'].'/'.$plugin['version'];
}
}
$piwigo_infos['general_stats']['nb_plugins'] = $piwigo_infos['general_stats']['nb_private_plugins'] + count($piwigo_infos['plugins']);
include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
$themes = new themes();
$piwigo_infos['general_stats']['nb_private_themes'] = 0;
$piwigo_infos['themes'] = array();
$private_themes = array();
foreach ($themes->db_themes_by_id as $theme)
{
$theme['state'] = 'active';
if ('active' == $theme['state'])
{
$eid = null;
if (isset($themes->fs_themes[ $theme['id'] ]))
{
$uri = $themes->fs_themes[ $theme['id'] ]['uri'];
if (preg_match('/eid=(\d+)/', $uri, $matches))
{
$eid = $matches[1];
}
}
if (empty($eid))
{
// let's search in the data fetched from PEM
$eid = $official_exts[ $conf['pem_themes_category'] ][ $theme['id'] ] ?? null;
}
// we must exclude "private extensions". A private extension :
//
// * has no eid
// * OR has un unknown theme_id among all "Archive root directory" in PEM
if (empty($eid))
{
$private_themes[ $theme['id'] ] = 1;
continue;
}
$piwigo_infos['themes'][] = (empty($eid) ? 'null' : '#'.$eid).'/'.$theme['id'].'/'.$theme['version'];
}
}
$piwigo_infos['general_stats']['nb_private_themes'] = count(array_keys($private_themes));
$piwigo_infos['general_stats']['nb_themes'] = $piwigo_infos['general_stats']['nb_private_themes'] + count($piwigo_infos['themes']);
$default_theme = get_default_theme();
if (isset($private_themes[$default_theme]))
{
$default_theme = 'private theme';
}
$piwigo_infos['general_stats']['default_theme'] = $default_theme;
$piwigo_infos['themes_usage'] = array();
$query = '
SELECT
theme,
COUNT(*) AS theme_counter
FROM '.USER_INFOS_TABLE.'
GROUP BY theme
ORDER BY theme
;';
$themes_used = query2array($query, 'theme', 'theme_counter');
foreach ($themes_used as $theme_used => $counter)
{
if (isset($private_themes[$theme_used]))
{
$theme_used = 'private theme';
}
@$piwigo_infos['themes_usage'][$theme_used] += $counter;
}
$piwigo_infos['general_stats']['default_language'] = get_default_language();
$query = '
SELECT
language,
COUNT(*) AS language_counter
FROM '.USER_INFOS_TABLE.'
GROUP BY language
ORDER BY language
;';
$piwigo_infos['languages_usage'] = query2array($query, 'language', 'language_counter');
$piwigo_infos['activities'] = array();
$piwigo_infos['general_stats']['nb_activities'] = 0;
$query = '
SELECT
object,
action,
COUNT(*) AS counter
FROM '.ACTIVITY_TABLE.'
WHERE object != \'system\'
GROUP BY object, action
;';
$activities = query2array($query);
foreach ($activities as $activity)
{
$piwigo_infos['general_stats']['nb_activities'] += $activity['counter'];
@$piwigo_infos['activities'][ $activity['object'] ][ $activity['action'] ] = $activity['counter'];
}
$label_for_system_object_id = array(
1 => 'core',
2 => 'plugin',
3 => 'theme',
);
$query = '
SELECT
object,
object_id,
action,
COUNT(*) AS counter
FROM '.ACTIVITY_TABLE.'
WHERE object = \'system\'
GROUP BY object, object_id, action
;';
$activities = query2array($query);
foreach ($activities as $activity)
{
@$piwigo_infos['activities'][ $activity['object'] ][ $label_for_system_object_id[ $activity['object_id'] ] ?? 'undefined' ][ $activity['action'] ] = $activity['counter'];
}
$watermark = ImageStdParams::get_watermark();
$piwigo_infos['features'] = array(
'use_watermark' => !empty($watermark->file) ? 'yes' : 'no',
);
$features = array(
'activate_comments',
'rate',
'log',
'history_guest',
'history_admin',
);
foreach ($features as $feature)
{
$piwigo_infos['features'][$feature] = $conf[$feature] ? 'yes' : 'no';
}
$url = conf_get_param('send_piwigo_infos_update_url', PHPWG_URL).'/ws.php';
$get_data = array(
'format' => 'php',
'method' => 'porg.installs.update',
'origin_hash' => $piwigo_infos['origin_hash'],
);
$post_data = array(
'data' => json_encode($piwigo_infos)
);
if (!fetchRemote($url, $result, $get_data, $post_data))
{
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] fetchRemote on '.$url.' method=porg.installs.update has failed');
// let's fake a last_notice so that we only try 1 day later
$last_notice = isset($conf['send_piwigo_infos_last_notice']) ? strtotime($conf['send_piwigo_infos_last_notice']) : time();
$last_notice += 24*60*60;
conf_update_param('send_piwigo_infos_last_notice', date('c', $last_notice));
}
else
{
conf_update_param('send_piwigo_infos_last_notice', date('c'));
}
echo '<pre>'; print_r($piwigo_infos); echo '</pre>';
conf_delete_param('send_piwigo_infos_running');
$logger->info('['.__FUNCTION__.'][exec='.$exec_id.'] executed in '.get_elapsed_time($start_time, get_moment()));
}
?>