function action()
 {
     $s = owa_coreAPI::serviceSingleton();
     // lookup method class
     $do = $s->getApiMethodClass($this->getParam('do'));
     if ($do) {
         // check credentials
         /* PERFORM AUTHENTICATION */
         if (array_key_exists('required_capability', $do)) {
             /* CHECK USER FOR CAPABILITIES */
             if (!owa_coreAPI::isCurrentUserCapable($do['required_capability'])) {
                 // doesn't look like the currentuser has the necessary priviledges
                 owa_coreAPI::debug('User does not have capability required by this controller.');
                 // auth user
                 $auth =& owa_auth::get_instance();
                 $status = $auth->authenticateUser();
                 // if auth was not successful then return login view.
                 if ($status['auth_status'] != true) {
                     return 'This method requires authentication.';
                 } else {
                     //check for needed capability again now that they are authenticated
                     if (!owa_coreAPI::isCurrentUserCapable($do['required_capability'])) {
                         return 'Your user does not have privileges to access this method.';
                     }
                 }
             }
         }
         //perform
         $map = owa_coreAPI::getRequest()->getAllOwaParams();
         echo owa_coreAPI::executeApiCommand($map);
     }
 }
 function action()
 {
     // fetch list of modules that require updates
     $s =& owa_coreAPI::serviceSingleton();
     $modules = $s->getModulesNeedingUpdates();
     //print_r($modules);
     //return;
     // foreach do update in order
     $error = false;
     foreach ($modules as $k => $v) {
         $ret = $s->modules[$v]->update();
         if ($ret != true) {
             $error = true;
             // if there is an error check to see if it's because the cli update mode is required
             $cli_update_required = $s->modules[$v]->isCliUpdateModeRequired();
             break;
         }
     }
     if ($error === true) {
         if ($cli_update_required) {
             $this->set('error_msg', $this->getMsg(3311));
         } else {
             $this->set('error_msg', $this->getMsg(3307));
         }
         $this->setView('base.error');
         $this->setViewMethod('delegate');
     } else {
         // add data to container
         $this->set('status_code', 3308);
         $this->set('do', 'base.optionsGeneral');
         $this->setViewMethod('redirect');
     }
 }
 function installSchema()
 {
     $service =& owa_coreAPI::serviceSingleton();
     $base = $service->getModule('base');
     $status = $base->install();
     return $status;
 }
 function action()
 {
     $service =& owa_coreAPI::serviceSingleton();
     $this->e->notice('starting Embedded install');
     //create config file
     $this->c->createConfigFile($this->params);
     $this->c->applyConfigConstants();
     // install schema
     $base = $service->getModule('base');
     $status = $base->install();
     // schema was installed successfully
     if ($status === true) {
         //create admin user
         $cu = owa_coreAPI::getCurrentUser();
         $this->createAdminUser($cu->getUserData('email_address'), $cu->getUserData('real_name'));
         // create default site
         $this->createDefaultSite($this->getParam('domain'), $this->getParam('name'), $this->getParam('description'), $this->getParam('site_family'), $this->getParam('site_id'));
         // Persist install complete flag.
         $this->c->persistSetting('base', 'install_complete', true);
         $save_status = $this->c->save();
         if ($save_status === true) {
             $this->e->notice('Install Complete Flag added to configuration');
         } else {
             $this->e->notice('Could not persist Install Complete Flag to the Database');
         }
         $this->setView('base.installFinishEmbedded');
         // schema was not installed successfully
     } else {
         $this->e->notice('Aborting embedded install due to errors installing schema. Try dropping all OWA tables and try again.');
         return false;
     }
 }
Ejemplo n.º 5
0
 function __construct()
 {
     $this->params = $this->getArgs();
     if (isset($this->params['interval'])) {
         $this->job_scheduling_interval = $this->params['interval'];
     }
     if (isset($this->params['max_workers'])) {
         $this->max_workers = $this->params['max_workers'];
     }
     if (isset($this->params['pid_file_location'])) {
         $this->pidFileLocation = $this->params['pid_file_location'];
     }
     if (isset($this->params['uid'])) {
         $this->userID = $this->params['uid'];
     }
     if (isset($this->params['gid'])) {
         $this->groupID = $this->params['gid'];
     }
     if (isset($this->params['pid_file_location'])) {
         $this->pidFileLocation = $this->params['pid_file_location'];
     }
     $s = owa_coreAPI::serviceSingleton();
     $this->jobs = $s->getMap('backgound_jobs');
     $this->eq = owa_coreAPI::getEventDispatch();
     return parent::__construct();
 }
 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);
             }
         }
     }
 }
Ejemplo n.º 7
0
 function action()
 {
     $service = owa_coreAPI::serviceSingleton();
     $im = owa_coreAPI::supportClassFactory('base', 'installManager');
     $this->e->notice('Starting OWA Install from command line.');
     //create config file
     $present = $this->c->isConfigFilePresent();
     if ($present) {
         $this->c->applyConfigConstants();
         // install schema
         $status = $im->installSchema();
         // schema was installed successfully
         if ($status === true) {
             //create admin user
             //owa_coreAPI::debug('password: '******'base', 'db_password') ) );
             $im->createAdminUser($this->getParam('email_address'), $this->getParam('real_name'), $this->c->get('base', 'db_password'));
             // create default site
             $im->createDefaultSite($this->getParam('domain'), $this->getParam('domain'), $this->getParam('description'), $this->getParam('site_family'));
             // Persist install complete flag.
             $this->c->persistSetting('base', 'install_complete', true);
             $save_status = $this->c->save();
             if ($save_status === true) {
                 $this->e->notice('Install Completed.');
             } else {
                 $this->e->notice('Could not persist Install Complete Flag to the Database');
             }
             // schema was not installed successfully
         } else {
             $this->e->notice('Aborting embedded install due to errors installing schema. Try dropping all OWA tables and try again.');
             return false;
         }
     } else {
         $this->e->notice("Could not locate config file. Aborting installation.");
     }
 }
 function action()
 {
     $s =& owa_coreAPI::serviceSingleton();
     $m = $s->getModule($this->getParam('module'));
     $m->deactivate();
     $this->setRedirectAction('base.optionsModules');
     $this->setStatusCode(2502);
 }
 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) {
                         // process event if needed
                         // lookup which event processor to use to process this event type
                         $processor_action = owa_coreAPI::getEventProcessor($event->getEventType());
                         if ($processor_action) {
                             // processor handles it's own event dispatching, so just return
                             return owa_coreAPI::handleRequest(array('event' => $event), $processor_action);
                         } else {
                             // 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 listPendingUpdates()
 {
     $s =& owa_coreAPI::serviceSingleton();
     $modules = $s->getModulesNeedingUpdates();
     if ($modules) {
         owa_coreAPI::notice(sprintf("Updates pending include: %s", print_r($modules, true)));
     } else {
         owa_coreAPI::notice("No updates are pending.");
     }
 }
Ejemplo n.º 11
0
 function getRequiredCapability()
 {
     $s = owa_coreAPI::serviceSingleton();
     // lookup method class
     $do = $s->getApiMethodClass($this->getParam('do'));
     if ($do) {
         // check for capability
         if (array_key_exists('required_capability', $do)) {
             return $do['required_capability'];
         }
     }
 }
Ejemplo n.º 12
0
 function up()
 {
     $db = owa_coreAPI::dbSingleton();
     $s =& owa_coreAPI::serviceSingleton();
     $entities = $s->modules[$this->module_name]->getEntities();
     foreach ($entities as $k => $v) {
         $ret = $db->alterTableType($this->c->get('base', 'ns') . $v, 'InnoDB');
         if ($ret == true) {
             $this->e->notice(sprintf('Changed Table %s to InnoDB', $v));
         } else {
             $this->e->notice(sprintf('Change to Table %s failed', $v));
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 13
0
 /**
  * Must be called before all other event property setting functions
  */
 function pre()
 {
     $teh = owa_coreAPI::getInstance('owa_trackingEventHelpers', OWA_BASE_CLASS_DIR . 'trackingEventHelpers.php');
     $s = owa_coreAPI::serviceSingleton();
     // STAGE 1 - set environmental properties from SERVER
     // now happens in coreAPI::logEvent
     // STAGE 2 - process incomming properties
     $properties = $s->getMap('tracking_properties_regular');
     // add custom var properties
     $properties = $teh->addCustomVariableProperties($properties);
     // translate custom var properties
     $teh->translateCustomVariables($this->event);
     $teh->setTrackerProperties($this->event, $properties);
     // STAGE 3 - derived properties
     $derived_properties = $s->getMap('tracking_properties_derived');
     $teh->setTrackerProperties($this->event, $derived_properties);
 }
Ejemplo n.º 14
0
 public static function getAllMetrics()
 {
     $s = owa_coreAPI::serviceSingleton();
     return $s->metrics;
 }
 static function resolveOs($os, $event)
 {
     $service = owa_coreAPI::serviceSingleton();
     $bcap = $service->getBrowscap();
     return $bcap->getOsFamily();
 }
 function getAllRelatedMetrics($entity)
 {
     $related_metrics = array();
     $s = owa_coreAPI::serviceSingleton();
     $all_metrics = $s->getAllMetrics();
     $entity_name = $entity->getName();
     $s = owa_coreAPI::serviceSingleton();
     $metricsByEntity = $s->getMap('metricsByEntity');
     foreach ($all_metrics as $metric_name => $implementations) {
         foreach ($implementations as $implementation) {
             $m = owa_coreAPI::metricFactory($implementation['class'], $implementation['params']);
             if ($m->isCalculated()) {
                 $children = $m->getChildMetrics();
                 $error = false;
                 foreach ($children as $child) {
                     if (!isset($metricsByEntity[$entity_name][$child])) {
                         $error = true;
                     }
                 }
                 if (!$error) {
                     $related_metrics[$implementation['group']][] = array('name' => $metric_name, 'label' => $implementation['label'], 'description' => $implementation['description'], 'group' => $implementation['group']);
                     continue;
                 }
             } else {
                 if ($entity_name === $m->getEntityName()) {
                     $related_metrics[$implementation['group']][] = array('name' => $metric_name, 'label' => $implementation['label'], 'description' => $implementation['description'], 'group' => $implementation['group']);
                     continue;
                 }
             }
         }
     }
     return $related_metrics;
 }
 /**
  * Notify handler method
  *
  * @param 	object $event
  * @access 	public
  */
 function notify($event)
 {
     $dispatch = owa_coreAPI::getEventDispatch();
     $ct = owa_coreAPI::entityFactory('base.commerce_transaction_fact');
     $pk = $ct->generateId($event->get('ct_order_id'));
     $ct->getByPk('id', $pk);
     $id = $ct->get('id');
     if (!$id) {
         // set missing properties from associated session
         // this is needed becuase the ecommerce transaction PHP API allows for
         // events to be fired into OWA from a non-web request by passing
         // the session_id.
         $original_session_id = $event->get('original_session_id');
         if ($original_session_id) {
             $s = owa_coreAPI::entityFactory('base.session');
             $s->load($original_session_id);
             // override the session id with original session id
             // this is needed for downstream events
             $event->set('session_id', $original_session_id);
             if ($s->get('id')) {
                 $ct->setProperties($s->_getProperties());
                 $ct->set('session_id', $original_session_id);
             } else {
                 owa_coreAPI::debug('Cannot find original session with id: ' . $original_session_id);
                 return OWA_EHS_EVENT_FAILED;
             }
         }
         $ct->setProperties($event->getProperties());
         $ct->set('id', $pk);
         // Generate Location Id. Location data is comming from user input NOT ip address
         if ($event->get('country')) {
             $s = owa_coreAPI::serviceSingleton();
             $location_id = $s->geolocation->generateId($event->get('country'), $event->get('state'), $event->get('city'));
             $ct->set('location_id', $location_id);
         }
         // set entity properties
         $ct->set('order_id', trim($event->get('ct_order_id')));
         $ct->set('order_source', trim(strtolower($event->get('ct_order_source'))));
         $ct->set('gateway', trim(strtolower($event->get('ct_gateway'))));
         $ct->set('total_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_total'), 2)));
         $ct->set('tax_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_tax'), 2)));
         $ct->set('shipping_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_shipping'), 2)));
         $ct->set('days_since_first_session', $event->get('days_since_first_session'));
         $ct->set('num_prior_sessions', $event->get('num_prior_sessions'));
         $ret = $ct->create();
         // persist line items
         if ($ret) {
             $items = $event->get('ct_line_items');
             if ($items) {
                 foreach ($items as $item) {
                     $ret = $this->persistLineItem($item, $event);
                 }
             }
         }
         if ($ret) {
             $sce = $dispatch->makeEvent('ecommerce.transaction_persisted');
             $sce->setProperties($event->getProperties());
             $dispatch->asyncNotify($sce);
         }
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         // dispatch event just incase downstream handlers need to be triggered.
         $sce = $dispatch->makeEvent('ecommerce.transaction_persisted');
         $sce->setProperties($event->getProperties());
         $dispatch->asyncNotify($sce);
         owa_coreAPI::debug('Not Persisting. Transaction already exists');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
Ejemplo n.º 18
0
 protected function registerEventQueue($name, $map)
 {
     $map['queue_name'] = $name;
     $s = owa_coreAPI::serviceSingleton();
     $s->setMapValue('event_queues', $name, $map);
 }
Ejemplo n.º 19
0
 function setGeolocation()
 {
     if (!$this->event->get('country')) {
         $location = owa_coreAPI::getGeolocationFromIpAddress($this->event->get('ip_address'));
         owa_coreAPI::debug('geolocation: ' . print_r($location, true));
         $this->event->set('country', $location->getCountry());
         $this->event->set('city', $location->getCity());
         $this->event->set('latitude', $location->getLatitude());
         $this->event->set('longitude', $location->getLongitude());
         $this->event->set('country_code', $location->getCountryCode());
         $this->event->set('state', $location->getState());
         $location_id = $location->generateId();
     } else {
         $s = owa_coreAPI::serviceSingleton();
         $location_id = $s->geolocation->generateId($this->event->get('country'), $this->event->get('state'), $this->event->get('city'));
     }
     if ($location_id) {
         $this->event->set('location_id', $location_id);
     }
 }
Ejemplo n.º 20
0
 /**
  * Logs tracking event from url params taken from request scope.
  * Takes event type from url.
  *
  * @return unknown
  */
 function logEventFromUrl($manage_state = false)
 {
     // keeps php executing even if the client closes the connection
     ignore_user_abort(true);
     $service =& owa_coreAPI::serviceSingleton();
     $service->request->decodeRequestParams();
     $event = owa_coreAPI::supportClassFactory('base', 'event');
     $event->setEventType(owa_coreAPI::getRequestParam('event_type'));
     $event->setProperties($service->request->getAllOwaParams());
     // check for third party cookie mode.
     $mode = owa_coreAPI::getRequestParam('thirdParty');
     if ($mode) {
         return $this->trackEvent($event);
     } else {
         return owa_coreAPI::logEvent($event->getEventType(), $event);
     }
 }
Ejemplo n.º 21
0
    }
    unset($params['action']);
    unset($params['do']);
} else {
    // No params found
    exit;
}
// Initialize owa
$owa =& new owa_php();
if ($owa->isEndpointEnabled(basename(__FILE__))) {
    // setting CLI mode to true
    $owa->setSetting('base', 'cli_mode', true);
    // setting user auth
    $owa->setCurrentUser('admin', 'cli-user');
    // run controller or view and echo page content
    $s = owa_coreAPI::serviceSingleton();
    $s->loadCliCommands();
    if (array_key_exists('cmd', $params)) {
        $cmd = $s->getCliCommandClass($params['cmd']);
        if ($cmd) {
            $params['do'] = $cmd;
            echo $owa->handleRequest($params);
        } else {
            echo "Invalid command name.";
        }
    } else {
        echo "Missing a command argument.";
    }
} else {
    // unload owa
    $owa->restInPeace();
 function registerBackgroundJob($name, $command, $cron_tab, $max_processes = 1)
 {
     $job = array('name' => $name, 'cron_tab' => $cron_tab, 'command' => $command, 'max_processes' => $max_processes);
     $s = owa_coreAPI::serviceSingleton();
     $s->setMapValue('background_jobs', $name, $job);
 }
 /**
  * Returns a configured javascript tracker for inclusion in your web page.
  * You can pass an options array to control what the tracker will log.
  * The options array is a key/value pair format like:
  *
  * $options = array('do_not_log_pageview' => true);
  *
  * Option keys include: 'do_not_log_pageview', 'do_not_log_clicks', 'do_not_log_domstream'
  *
  * @param 	$echo		bool 	if true the function will echo. if false the tracker is returned asa string.
  * @param	$options	array	an key value pair option array 
  * @return 	$tag 		string	the tracker javascript.
  */
 function placeHelperPageTags($echo = true, $options = array())
 {
     if (!owa_coreAPI::getRequestParam('is_robot')) {
         // check to see if first hit tag is needed
         if (isset($options['delay_first_hit']) || owa_coreAPI::getSetting('base', 'delay_first_hit')) {
             $service =& owa_coreAPI::serviceSingleton();
             //check for persistant cookie
             $v = $service->request->getOwaCookie('v');
             if (empty($v)) {
                 $options['first_hit_tag'] = true;
             }
         }
         if (!class_exists('owa_template')) {
             require_once OWA_BASE_CLASSES_DIR . 'owa_template.php';
         }
         $t = new owa_template();
         $t->set_template('js_helper_tags.tpl');
         $tracking_code = owa_coreAPI::getJsTrackerTag($this->getSiteId(), $options);
         $t->set('tracking_code', $tracking_code);
         $tag = $t->fetch();
         if ($echo == false) {
             return $tag;
         } else {
             echo $tag;
         }
     }
 }
 /**
  * Notify handler method
  *
  * @param 	object $event
  * @access 	public
  */
 function notify($event)
 {
     $dispatch = owa_coreAPI::getEventDispatch();
     $ct = owa_coreAPI::entityFactory('base.commerce_transaction_fact');
     $pk = $ct->generateId($event->get('ct_order_id'));
     $ct->getByPk('id', $pk);
     $id = $ct->get('id');
     $resulting_event_name = 'ecommerce.transaction_persisted';
     // The ecommerce transaction PHP API allows for
     // events to be fired into OWA from a non-web request by passing
     // the original_session_id.
     $original_session_id = $event->get('original_session_id');
     // look up properties from the orieginal session and add them to the transaction event.
     if ($original_session_id) {
         // change the resulting evnt name so that downstream handers know that dimensions
         // were already persisted.
         $resulting_event_name = 'ecommerce.async_transaction_persisted';
         // set the session id with original session id
         $event->set('session_id', $original_session_id);
         // load the original session
         $s = owa_coreAPI::entityFactory('base.session');
         $s->load($original_session_id);
         if ($s->get('id')) {
             // add properties from retrieved session into the commerce transaction event
             // this is needed for downstream events that do not know or care that the
             // transaction event was generated via the REST API.
             $osession_properties = $s->_getProperties();
             // remove the entity 'id' and other property that do not need to be merged.
             unset($osession_properties['id']);
             // do not overwrite existing properties.
             $event->setNewProperties($osession_properties);
         } else {
             owa_coreAPI::debug('Cannot find original session with id: ' . $original_session_id);
             return OWA_EHS_EVENT_FAILED;
         }
     }
     // check to see if the transaction was already persisted.
     if (!$id) {
         $ct->setProperties($event->getProperties());
         $ct->set('id', $pk);
         // Generate Location Id. Location data is comming from user input NOT ip address
         if ($event->get('country')) {
             $s = owa_coreAPI::serviceSingleton();
             $location_id = $s->geolocation->generateId($event->get('country'), $event->get('state'), $event->get('city'));
             $ct->set('location_id', $location_id);
         }
         // set entity properties
         $ct->set('order_id', trim($event->get('ct_order_id')));
         $ct->set('order_source', trim(strtolower($event->get('ct_order_source'))));
         $ct->set('gateway', trim(strtolower($event->get('ct_gateway'))));
         $ct->set('total_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_total'), 2)));
         $ct->set('tax_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_tax'), 2)));
         $ct->set('shipping_revenue', owa_lib::prepareCurrencyValue(round($event->get('ct_shipping'), 2)));
         $ct->set('days_since_first_session', $event->get('days_since_first_session'));
         $ct->set('num_prior_sessions', $event->get('num_prior_sessions'));
         $ret = $ct->create();
         // persist line items
         if ($ret) {
             $items = $event->get('ct_line_items');
             if ($items) {
                 foreach ($items as $item) {
                     $ret = $this->persistLineItem($item, $event);
                 }
             }
         }
         if ($ret) {
             $sce = $dispatch->makeEvent($resulting_event_name);
             $sce->setProperties($event->getProperties());
             $dispatch->asyncNotify($sce);
         }
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not Persisting. Transaction already exists');
         // dispatch event just in case downstream handlers need to be triggered.
         $sce = $dispatch->makeEvent($resulting_event_name);
         $sce->setProperties($event->getProperties());
         $dispatch->asyncNotify($sce);
         return OWA_EHS_EVENT_HANDLED;
     }
 }