Révision 60283730
Ajouté par Assos Assos il y a presque 6 ans
drupal7/sites/all/modules/piwik/piwik.install | ||
---|---|---|
68 | 68 |
$t = get_t(); |
69 | 69 |
|
70 | 70 |
switch ($phase) { |
71 |
case 'install': |
|
72 |
if (module_exists('matomo')) { |
|
73 |
// https://matomo.org/blog/2018/01/piwik-is-now-matomo/ |
|
74 |
$requirements['piwik_matomo_is_installed'] = array( |
|
75 |
'title' => $t('Piwik is now Matomo!'), |
|
76 |
'value' => $t('Fails'), |
|
77 |
'severity' => REQUIREMENT_ERROR, |
|
78 |
'description' => $t('Piwik has been renamed to Matomo Analytics. Piwik module is blocked now and cannot re-enabled! Please remove piwik module from your system. It is no longer used.'), |
|
79 |
); |
|
80 |
} |
|
81 |
break; |
|
82 |
|
|
71 | 83 |
case 'runtime': |
72 | 84 |
// Module cannot validate piwik URL without external HTTP requests. |
73 | 85 |
if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) { |
... | ... | |
268 | 280 |
return t('Custom extensions for download tracking setting found. Update skipped!'); |
269 | 281 |
} |
270 | 282 |
} |
283 |
|
|
284 |
/** |
|
285 |
* Install Matomo module and migrate all settings. |
|
286 |
*/ |
|
287 |
function piwik_update_7206(&$sandbox) { |
|
288 |
// Make the update hook failing so it can re-run later again. |
|
289 |
if (!module_load_include('module', 'matomo', 'matomo')) { |
|
290 |
throw new DrupalUpdateException(t('Matomo module is missing. Download it and re-run update.php')); |
|
291 |
} |
|
292 |
|
|
293 |
$module_enabled = module_enable(array('matomo')); |
|
294 |
if ($module_enabled) { |
|
295 |
$messages[] = t('Successfully installed matomo module.'); |
|
296 |
|
|
297 |
$piwik_cache = variable_get('piwik_cache', 0); |
|
298 |
$piwik_codesnippet_before = variable_get('piwik_codesnippet_before', ''); |
|
299 |
$piwik_codesnippet_after = variable_get('piwik_codesnippet_after', ''); |
|
300 |
$piwik_custom = variable_get('piwik_custom', 0); |
|
301 |
$piwik_custom_var = variable_get('piwik_custom_var', array()); |
|
302 |
$piwik_domain_mode = variable_get('piwik_domain_mode', 0); |
|
303 |
$piwik_js_scope = variable_get('piwik_js_scope', 'header'); |
|
304 |
$piwik_last_cache = variable_get('piwik_last_cache', 0); |
|
305 |
$piwik_page_title_hierarchy = variable_get('piwik_page_title_hierarchy', FALSE); |
|
306 |
$piwik_page_title_hierarchy_exclude_home = variable_get('piwik_page_title_hierarchy_exclude_home', TRUE); |
|
307 |
$piwik_pages = variable_get('piwik_pages', "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*"); |
|
308 |
$piwik_privacy_donottrack = variable_get('piwik_privacy_donottrack', 1); |
|
309 |
$piwik_roles = variable_get('piwik_roles', array()); |
|
310 |
$piwik_site_id = variable_get('piwik_site_id', ''); |
|
311 |
$piwik_site_search = variable_get('piwik_site_search', FALSE); |
|
312 |
$piwik_trackcolorbox = variable_get('piwik_trackcolorbox', 1); |
|
313 |
$piwik_trackmailto = variable_get('piwik_trackmailto', 1); |
|
314 |
$piwik_track = variable_get('piwik_track', 1); |
|
315 |
$piwik_trackfiles_extensions = variable_get('piwik_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip'); |
|
316 |
$piwik_trackmessages = variable_get('piwik_trackmessages', array()); |
|
317 |
$piwik_trackuserid = variable_get('piwik_trackuserid', 0); |
|
318 |
$piwik_translation_set = variable_get('piwik_translation_set', 0); |
|
319 |
$piwik_url_http = variable_get('piwik_url_http', ''); |
|
320 |
$piwik_url_https = variable_get('piwik_url_https', ''); |
|
321 |
$piwik_visibility_pages = variable_get('piwik_visibility_pages', 0); |
|
322 |
$piwik_visibility_roles = variable_get('piwik_visibility_roles', 0); |
|
323 |
|
|
324 |
variable_set('matomo_cache', $piwik_cache); |
|
325 |
variable_set('matomo_codesnippet_before', $piwik_codesnippet_before); |
|
326 |
variable_set('matomo_codesnippet_after', $piwik_codesnippet_after); |
|
327 |
variable_set('matomo_custom', $piwik_custom); |
|
328 |
variable_set('matomo_custom_var', $piwik_custom_var); |
|
329 |
variable_set('matomo_domain_mode', $piwik_domain_mode); |
|
330 |
variable_set('matomo_js_scope', $piwik_js_scope); |
|
331 |
variable_set('matomo_last_cache', $piwik_last_cache); |
|
332 |
variable_set('matomo_page_title_hierarchy', $piwik_page_title_hierarchy); |
|
333 |
variable_set('matomo_page_title_hierarchy_exclude_home', $piwik_page_title_hierarchy_exclude_home); |
|
334 |
variable_set('matomo_pages', $piwik_pages); |
|
335 |
variable_set('matomo_privacy_donottrack', $piwik_privacy_donottrack); |
|
336 |
variable_set('matomo_roles', $piwik_roles); |
|
337 |
variable_set('matomo_site_id', $piwik_site_id); |
|
338 |
variable_set('matomo_site_search', $piwik_site_search); |
|
339 |
variable_set('matomo_trackcolorbox', $piwik_trackcolorbox); |
|
340 |
variable_set('matomo_trackmailto', $piwik_trackmailto); |
|
341 |
variable_set('matomo_track', $piwik_track); |
|
342 |
variable_set('matomo_trackfiles_extensions', $piwik_trackfiles_extensions); |
|
343 |
variable_set('matomo_trackmessages', $piwik_trackmessages); |
|
344 |
variable_set('matomo_trackuserid', $piwik_trackuserid); |
|
345 |
variable_set('matomo_translation_set', $piwik_translation_set); |
|
346 |
variable_set('matomo_url_http', $piwik_url_http); |
|
347 |
variable_set('matomo_url_https', $piwik_url_https); |
|
348 |
variable_set('matomo_visibility_pages', $piwik_visibility_pages); |
|
349 |
variable_set('matomo_visibility_roles', $piwik_visibility_roles); |
|
350 |
|
|
351 |
$messages[] = t('Copied settings from piwik to matomo module.'); |
|
352 |
|
|
353 |
// Remove matomo default permissions or duplicate 'rid' error occurs. |
|
354 |
db_delete('role_permission') |
|
355 |
->condition('module', 'matomo') |
|
356 |
->execute(); |
|
357 |
|
|
358 |
// Migrate piwik permissions to matomo. |
|
359 |
$permissions = array( |
|
360 |
'administer piwik' => 'administer matomo', |
|
361 |
'opt-in or out of tracking' => 'opt-in or out of matomo tracking', |
|
362 |
'use PHP for tracking visibility' => 'use php for matomo tracking visibility', |
|
363 |
'add JS snippets for piwik' => 'add js snippets for matomo', |
|
364 |
); |
|
365 |
foreach ($permissions as $permission_old_key => $permission_new_key) { |
|
366 |
db_update('role_permission') |
|
367 |
->fields(array( |
|
368 |
'permission' => $permission_new_key, |
|
369 |
'module' => 'matomo', |
|
370 |
)) |
|
371 |
->condition(db_and() |
|
372 |
->condition('permission', $permission_old_key) |
|
373 |
->condition('module', 'piwik') |
|
374 |
) |
|
375 |
->execute(); |
|
376 |
} |
|
377 |
|
|
378 |
// Clear the user access cache. |
|
379 |
drupal_static_reset('user_access'); |
|
380 |
drupal_static_reset('user_role_permissions'); |
|
381 |
$messages[] = t('Moved piwik permissions to matomo module.'); |
|
382 |
|
|
383 |
// Disable piwik modules depending on piwik or the migration will fail. |
|
384 |
$module_disable = module_disable(array('piwik'), FALSE); |
|
385 |
if (!module_exists('piwik')) { |
|
386 |
$messages[] = t('Successfully disabled piwik module.'); |
|
387 |
} |
|
388 |
else { |
|
389 |
$messages[] = t('FAILED to disable piwik module.'); |
|
390 |
|
|
391 |
// Unconfigure piwik to remove piwik tracking code; if piwik module may failed to disable. |
|
392 |
variable_set('piwik_site_id', ''); |
|
393 |
$messages[] = t('Unconfigured site id in piwik module to disable double tracking.'); |
|
394 |
} |
|
395 |
|
|
396 |
// Uninstall piwik module. |
|
397 |
$module_uninstalled = drupal_uninstall_modules(array('piwik'), FALSE); |
|
398 |
if ($module_uninstalled) { |
|
399 |
// Drupal does not remove all entries as the piwik hook is currently running. |
|
400 |
db_delete('system') |
|
401 |
->condition('name', 'piwik') |
|
402 |
->execute(); |
|
403 |
db_delete('cache_bootstrap') |
|
404 |
->condition('cid', 'system_list') |
|
405 |
->execute(); |
|
406 |
|
|
407 |
$messages[] = t('Successfully uninstalled piwik module. Please remove piwik from your system.'); |
|
408 |
drupal_set_message('Piwik is now Matomo! Matomo has been installed. Please remove Piwik module from your system.', 'warning'); |
|
409 |
} |
|
410 |
else { |
|
411 |
$messages[] = t('FAILED to uninstall piwik module.'); |
|
412 |
} |
|
413 |
} |
|
414 |
|
|
415 |
return empty($messages) ? t('FAILED to migrate piwik to matomo module. Please uninstall piwik module and install matomo module manually!') : implode(' ', $messages); |
|
416 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules