Exemplo n.º 1
0
 function _logMessage($msg, $status = DLOG_NOTICE)
 {
     if ($status & DLOG_TO_CONSOLE) {
         echo $msg . "\n";
     }
     owa_coreAPI::notice("Daemon: {$msg}");
 }
 function action()
 {
     if ($this->getParam('queues')) {
         $queues = $this->getParam('queues');
     } else {
         $queues = 'incoming_tracking_events,processing';
     }
     if ($this->getParam('interval')) {
         $interval = $this->getParam('interval');
     } else {
         $interval = 3600 * 24;
     }
     // pull list of event queues to process from command line
     $queues = $this->getParam('queues');
     if ($queues) {
         // parse command line
         $queues = explode(',', $this->getParam('queues'));
     } else {
         // get whatever queues are registered by modules
         $s = owa_coreAPI::serviceSingleton();
         $queues = array_keys($s->getMap('event_queues'));
     }
     if ($queues) {
         foreach ($queues as $queue_name) {
             owa_coreAPI::notice("About to prune archive of event queue: {$queue_name}");
             $q = owa_coreAPI::getEventQueue($queue_name);
             if ($q->connect()) {
                 $q->pruneArchive($interval);
             }
         }
     }
 }
 function action()
 {
     $sm = owa_coreAPI::supportClassFactory('base', 'siteManager');
     $ret = $sm->createNewSite($this->getParam('domain'), $this->getParam('name'), $this->getParam('description'), $this->getParam('site_family'));
     if ($ret) {
         owa_coreAPI::notice("Site added successfully. site_id: {$ret}");
     }
 }
 function action()
 {
     $module = $this->getParam('module');
     if ($module) {
         $ret = owa_coreAPI::activateModule($module);
     } else {
         owa_coreAPI::notice('No module argument was specified. Use module=xxx');
     }
 }
 /**
  * Constructor
  *
  * @param array $params
  * @return owa_controller
  */
 function __construct($params)
 {
     if (owa_coreAPI::getSetting('base', 'cli_mode')) {
         return parent::__construct($params);
     } else {
         owa_coreAPI::notice("Controller not called from CLI");
         exit;
     }
 }
Exemplo n.º 6
0
 function isDbReady()
 {
     $this->db_file_path = OWA_MAXMIND_DATA_DIR . $this->db_file_name;
     if (file_exists($this->db_file_path)) {
         $this->db_file_present = true;
     } else {
         owa_coreAPI::notice('Maxmind DB file could is not present at: ' . OWA_MAXMIND_DATA_DIR);
     }
     return $this->db_file_present;
 }
 /**
  * Constructor
  *
  * @return owa_hostip
  */
 function __construct()
 {
     if (!defined('OWA_MAXMIND_DATA_DIR')) {
         define('OWA_MAXMIND_DATA_DIR', OWA_DATA_DIR . 'maxmind/');
     }
     $this->db_file_path = OWA_MAXMIND_DATA_DIR . $this->db_file_name;
     if (file_exists($this->db_file_path)) {
         $this->db_file_present = true;
     } else {
         owa_coreAPI::notice('Maxmind DB file could is not present at: ' . OWA_MAXMIND_DATA_DIR);
     }
     return parent::__construct();
 }
 function action()
 {
     if ($this->getParam('queues')) {
         $queues = $this->getParam('queues');
     } else {
         $queues = 'incoming_tracking_events,processing';
     }
     owa_coreAPI::notice("About to process event queues: {$queues}");
     // pull list of event queues to process from command line
     $queues = $this->getParam('queues');
     if ($queues) {
         // parse command line
         $queues = explode(',', $this->getParam('queues'));
     } else {
         // get whatever queues are registered by modules
         $s = owa_coreAPI::serviceSingleton();
         $queues = array_keys($s->getMap('event_queues'));
     }
     if ($queues) {
         foreach ($queues as $queue_name) {
             $q = owa_coreAPI::getEventQueue($queue_name);
             if ($q->connect()) {
                 $d = owa_coreAPI::getEventDispatch();
                 $more = true;
                 while ($more) {
                     owa_coreAPI::debug('calling receive message');
                     // get an item from the queue
                     $event = $q->receiveMessage();
                     owa_coreAPI::debug('Event returned: ' . print_r($event, true));
                     if ($event) {
                         // dispatch event
                         $ret = $d->notify($event);
                         if ($ret = OWA_EHS_EVENT_HANDLED) {
                             // delete event from queue
                             // second param is for backwards compat. remove soon
                             $q->deleteMessage($event->getQueueGuid());
                         }
                     } else {
                         // if no event, stop the loop
                         $more = false;
                         owa_coreAPI::notice("No more events to process.");
                     }
                 }
                 $q->disconnect();
             }
         }
     } else {
         owa_coreAPI::notice("There are no event queues registered.");
     }
 }
 function action()
 {
     $c = owa_coreAPI::configSingleton();
     $config_values = $this->get('config');
     if (!empty($config_values)) {
         foreach ($config_values as $k => $v) {
             list($module, $name) = explode('.', $k);
             if ($module && $name) {
                 $c->persistSetting($module, $name, $v);
             }
         }
         $c->save();
         owa_coreAPI::notice("Configuration changes saved to database.");
         $this->setStatusCode(2500);
     }
     $this->setRedirectAction('base.optionsGeneral');
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     if ($event->get('document_id') || $event->get('page_url')) {
         // create entity
         $d = owa_coreAPI::entityFactory('base.document');
         // get document id from event
         $id = $event->get('document_id');
         // if no document_id present attempt to make one from the page_url property
         if (!$id) {
             $page_url = $event->get('page_url');
             if ($page_url) {
                 $id = $d->generateId($page_url);
             } else {
                 owa_coreAPI::debug('Not persisting Document, no page_url or document_id event property found.');
                 return OWA_EHS_EVENT_HANDLED;
             }
         }
         $d->load($id);
         if (!$d->wasPersisted()) {
             $d->setProperties($event->getProperties());
             $d->set('url', $event->get('page_url'));
             $d->set('uri', $event->get('page_uri'));
             $d->set('id', $id);
             $ret = $d->create();
             if ($ret) {
                 return OWA_EHS_EVENT_HANDLED;
             } else {
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             owa_coreAPI::debug('Not logging Document, already exists');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         owa_coreAPI::notice('Not persisting Document dimension. document id or page url are missing from event.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
Exemplo n.º 11
0
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     if (!$event->get('host_id')) {
         owa_coreAPI::notice('Not persisting host dimension. Host id missing from event.');
         return OWA_EHS_EVENT_HANDLED;
     }
     $h = owa_coreAPI::entityFactory('base.host');
     $h->getByPk('id', $event->get('host_id'));
     $id = $h->get('id');
     if (!$id) {
         $h->setProperties($event->getProperties());
         $h->set('id', $event->get('host_id'));
         $ret = $h->create();
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not Persisting. Host already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function isLocked()
 {
     if (file_exists($this->lock_file)) {
         //read contents of lock file for last PID
         $lock = fopen($this->lock_file, "r") or die("Could not read lock file");
         if ($lock) {
             while (!feof($lock)) {
                 $former_pid = fgets($lock, 4096);
             }
             fclose($lock);
         }
         //check to see if former process is still running
         $ps_check = $this->isRunning($former_pid);
         //if the process is still running, exit.
         if ($ps_check) {
             owa_coreAPI::notice(sprintf('Previous Process (%d) still active. Terminating Run.', $former_pid));
             return true;
             //if it's not running remove the lock file and proceead.
         } else {
             owa_coreAPI::debug(sprintf('Process %d is no longer running. Deleting old Lock file. \\n', $former_pid));
             unlink($this->lock_file);
             return false;
         }
     } else {
         return false;
     }
 }
Exemplo n.º 13
0
 function markAsHandled($item_id)
 {
     $qi = owa_coreAPI::entityFactory('base.queue_item');
     $qi->load($item_id);
     if ($qi->wasPersisted()) {
         $qi->set('status', 'handled');
         $qi->set('handled_timestamp', $this->makeTimestamp());
         $qi->save();
     } else {
         owa_coreAPI::notice("Could not find/delete queue item id: {$item_id}");
     }
 }
 /**
  * Checks for and applies schema upgrades for the module
  *
  */
 function update()
 {
     // list files in a directory
     $files = owa_lib::listDir(OWA_DIR . 'modules' . '/' . $this->name . '/' . 'updates', false);
     //print_r($files);
     $current_schema_version = $this->c->get($this->name, 'schema_version');
     // extract sequence
     foreach ($files as $k => $v) {
         // the use of %d casts the sequence number as an int which is critical for maintaining the
         // order of the keys in the array that we are going ot create that holds the update objs
         //$n = sscanf($v['name'], '%d_%s', $seq, $classname);
         $seq = substr($v['name'], 0, -4);
         settype($seq, "integer");
         if ($seq > $current_schema_version) {
             if ($seq <= $this->required_schema_version) {
                 $this->updates[$seq] = owa_coreAPI::updateFactory($this->name, substr($v['name'], 0, -4));
                 // if the cli update mode is required and we are not running via cli then return an error.
                 owa_coreAPI::debug('cli update mode required: ' . $this->updates[$seq]->isCliModeRequired());
                 if ($this->updates[$seq]->isCliModeRequired() === true && !defined('OWA_CLI')) {
                     //set flag in module
                     $this->update_from_cli_required = true;
                     owa_coreAPI::notice("Aborting update {$seq}. This update must be applied using the command line interface.");
                     return false;
                 }
                 // set schema version from sequence number in file name. This ensures that only one update
                 // class can ever be in use for a particular schema version
                 $this->updates[$seq]->schema_version = $seq;
             }
         }
     }
     // sort the array
     ksort($this->updates, SORT_NUMERIC);
     //print_r(array_keys($this->updates));
     foreach ($this->updates as $k => $obj) {
         $this->e->notice(sprintf("Applying Update %d (%s)", $k, get_class($obj)));
         $ret = $obj->apply();
         if ($ret == true) {
             $this->e->notice("Update Suceeded");
         } else {
             $this->e->notice("Update Failed");
             return false;
         }
     }
     return true;
 }
 function flush()
 {
     owa_coreAPI::notice("Cannot flush Memcache from client.");
     return true;
 }
 function rollback($update)
 {
     list($module, $seq) = explode('.', $update);
     $u = owa_coreAPI::updateFactory($module, $seq);
     $u->rollback();
     owa_coreAPI::notice("Rollback completed.");
 }
 /**
  * Create Table
  *
  * Handled by DB abstraction layer because the SQL associated with this is way too DB specific
  */
 function createTable()
 {
     $db = owa_coreAPI::dbSingleton();
     // Persist table
     $status = $db->createTable($this);
     if ($status == true) {
         owa_coreAPI::notice(sprintf("%s Table Created.", $this->getTableName()));
         return true;
     } else {
         owa_coreAPI::notice(sprintf("%s Table Creation Failed.", $this->getTableName()));
         return false;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     if ($event->get('location_id') || $event->get('ip_address')) {
         $h = owa_coreAPI::entityFactory('base.location_dim');
         // look for location id on the event. This happens when
         // another event has already created it.
         if ($event->get('location_id')) {
             $location_id = $event->get('location_id');
             // else look to see if he event has the minimal geo properties
             // if it does then assume that geo properties are set.
         } elseif ($event->get('country')) {
             $key = $event->get('country') . $event->get('city');
             $location_id = $h->generateId($key);
             // load the geo properties from the geo service.
         } else {
             $location = owa_coreAPI::getGeolocationFromIpAddress($event->get('ip_address'));
             owa_coreAPI::debug('geolocation: ' . print_r($location, true));
             //set properties of the session
             $event->set('country', $location->getCountry());
             $event->set('city', $location->getCity());
             $event->set('latitude', $location->getLatitude());
             $event->set('longitude', $location->getLongitude());
             $event->set('country_code', $location->getCountryCode());
             $event->set('state', $location->getState());
             $key = $event->get('country') . $event->get('city');
             $location_id = $h->generateId($key);
         }
         // look up the county code if it's missing
         if (!$event->get('country_code') && $event->get('country')) {
             $event->set('country_code', $this->lookupCountryCodeFromName($event->get('country')));
         }
         $h->getByPk('id', $location_id);
         $id = $h->get('id');
         if (!$id) {
             $location = owa_coreAPI::getGeolocationFromIpAddress($event->get('ip_address'));
             owa_coreAPI::debug('geolocation: ' . print_r($location, true));
             //set properties of the session
             $h->set('country', $event->get('country'));
             $h->set('city', $event->get('city'));
             $h->set('latitude', $event->get('latitude'));
             $h->set('longitude', $event->get('longitude'));
             $h->set('country_code', $event->get('country_code'));
             $h->set('state', $event->get('state'));
             $h->set('id', $location_id);
             $ret = $h->create();
             if ($ret) {
                 return OWA_EHS_EVENT_HANDLED;
             } else {
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             owa_coreAPI::debug('Not Logging. Location already exists');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         owa_coreAPI::notice('Not persisting location dimension. Location id or ip address missing from event.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function pruneArchive($interval)
 {
     if (is_dir($this->archive_path)) {
         foreach (new DirectoryIterator($this->archive_path) as $item) {
             if ($item->isFile() && !$item->isDot() && $item->getMTime() < time() - $interval) {
                 owa_coreAPI::notice('about to unlink' . $item->getRealPath());
                 $this->deleteFile($item->getRealPath());
             }
         }
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $update = false;
     $conversion_info = $this->checkForConversion($event);
     // check for conversion
     if ($conversion_info) {
         // check for needed session_id
         if ($event->get('session_id')) {
             // load session
             $s = owa_coreAPI::entityFactory('base.session');
             $s->load($event->get('session_id'));
             // if session exists
             if ($s->wasPersisted()) {
                 //record conversion
                 if (!empty($conversion_info['conversion'])) {
                     $goal_column = 'goal_' . $conversion_info['conversion'];
                     $already = $s->get($goal_column);
                     // see if an existing value has been set goal value
                     $goal_value_column = 'goal_' . $conversion_info['conversion'] . '_value';
                     $existing_value = $s->get($goal_value_column);
                     $value = $conversion_info['value'];
                     // determin is we have a conversion event worth updating
                     // only record one goal of a particular type per session
                     if ($already != true) {
                         // there is a goal conversion
                         $s->set($goal_column, true);
                         $update = true;
                         owa_coreAPI::debug("{$goal_column} was achieved.");
                     } else {
                         // goal already happened but check to see if we need to add a value to it.
                         // happens in the case of ecommerce transaction where the value
                         // can come in a secondary request. if no value then return.
                         if (!$value) {
                             owa_coreAPI::debug('Not updating session. Goal was already achieved and in same session.');
                             return OWA_EHS_EVENT_HANDLED;
                         }
                     }
                     // Allow a value to be set if one has not be set already.
                     // this is needed to support dynamic values passed by commerce transaction events
                     if ($value && !$existing_value) {
                         $s->set($goal_value_column, owa_lib::prepareCurrencyValue($value));
                         $update = true;
                     }
                 }
                 //record goal start
                 if (!empty($conversion_info['start'])) {
                     $goal_start_column = 'goal_' . $conversion_info['start'] . '_start';
                     $already_started = $s->get($goal_start_column);
                     if ($already_started != true) {
                         $s->set($goal_start_column, true);
                         $update = true;
                         owa_coreAPI::debug("{$goal_start_column} was started.");
                     } else {
                         owa_coreAPI::debug("{$goal_start_column} was already started.");
                     }
                 }
                 //update object
                 if ($update) {
                     // summarize goal conversions
                     $s->set('num_goals', $this->countGoalConversions($s));
                     // summarize goal conversion value
                     $s->set('goals_value', $this->sumGoalValues($s));
                     // summarize goal starts
                     $s->set('num_goal_starts', $this->countGoalStarts($s));
                     $ret = $s->update();
                     if ($ret) {
                         // create a new_conversion event so that the total conversion
                         // metrics can be resummarized
                         $this->dispatchNewConversionEvent($event);
                         return OWA_EHS_EVENT_HANDLED;
                     } else {
                         return OWA_EHS_EVENT_FAILED;
                     }
                 } else {
                     owa_coreAPI::debug("nothing about this conversion is worth updating.");
                     return OWA_EHS_EVENT_HANDLED;
                 }
             } else {
                 owa_coreAPI::debug("Conversion processing aborted. No session could be found.");
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             owa_coreAPI::notice('Not persisting conversion. Session id missing from event.');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         owa_coreAPI::debug('No goal start or conversion detected.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }