Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Cleanup any CiviCRM session state after uninstallation. | |
6 | */ | |
7 | ||
8 | if (!defined('CIVI_SETUP')) { | |
9 | exit("Installation plugins must only be loaded by the installer.\n"); | |
10 | } | |
11 | ||
12 | \Civi\Setup::dispatcher() | |
13 | ->addListener('civi.setup.uninstallDatabase', function (\Civi\Setup\Event\UninstallDatabaseEvent $e) { | |
14 | $supportedCms = array('Drupal', 'Backdrop'); | |
15 | if (!in_array($e->getModel()->cms, $supportedCms)) { | |
16 | return; | |
17 | } | |
18 | \Civi\Setup::log()->info('[CleanupDrupalSession.civi-setup.php] Purge Drupal session state which have stale CiviCRM references'); | |
19 | ||
20 | // This keeps the Drupal user logged in, but it purges any data. | |
21 | ||
22 | // It's a bit ham-handed, but no one provides an API like this, and a | |
23 | // more surgical approach would get messy (due to variations of session-encoding), | |
24 | // and... it seems to work... | |
25 | ||
26 | db_query('UPDATE sessions SET session = NULL'); | |
27 | ||
28 | // foreach(db_query('SELECT sid FROM sessions') as $sid) { | |
29 | // $sessionResult = db_query('SELECT session FROM sessions WHERE sid = :sid', array( | |
30 | // 'sid' => $sid->sid, | |
31 | // )); | |
32 | // foreach ($sessionResult as $session) { | |
33 | // $data = session_decode($session->session); // blerg, nothign does this right :( | |
34 | // print_r(['sr'=>$session, 'data'=>$data]); | |
35 | // if (!empty($data['CiviCRM'])) { | |
36 | // echo "must clear " . $sid->sid . "\n"; | |
37 | // unset($data['CiviCRM']); | |
38 | // reserialize and write back to DB | |
39 | // } | |
40 | // else { | |
41 | // echo "ignore " . $sid->sid . "\n"; | |
42 | // } | |
43 | // | |
44 | // } | |
45 | // } | |
46 | }); |