CMS  Version 3.9
migrate_data.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("activity_tracker", "process");
3 Fakoli::assertRole("admin");
4 
5 if (!$process)
6 {
7  // We are in a user request - spawn the background process and return the ID
8 
9  $process = new ProcessManager();
10  echo $process->run("/action/activity_tracker/migrate_data");
11 }
12 else
13 {
14  echo "Executing migration script";
15 
16  try
17  {
18  $process->setProgress("Running", "Materializing Session Records", 5);
19 
20  $db = ConnectionManager::getConnection();
21  $db->exec("INSERT INTO user_activity_session (session_identifier, user_id, session_start, session_end, request_count) select session_id, user_id, session_start, session_end, page_views from activity_sessions");
22 
23  $process->setProgress("Running", "Retrieving Session summaries", 10);
24 
25  $sessions = IteratedQuery::create(ActivitySession, "")->execute();
26 
27  $max = count($sessions);
28  $count = 1;
29 
30  foreach($sessions as $session)
31  {
32  $process->setProgress("Running", "Migrating $count of $max", number_format(10 + ($count * 90 / $max), 1));
33  ActivityTracker::migrateData($session);
34  ++$count;
35  }
36 
37  $process->setProgress("Completed", "All done!", 100);
38  }
39  catch(Exception $e)
40  {
41  $process->setProgress("Error", $e->getMessage(), 100);
42  }
43 }
44 
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
Definition: core.inc:297
Provides a central management class for event handlers and common functionality for the process compo...
$db
$max
$sessions
$count
$process
Definition: run.php:54