Exemplo n.º 1
0
 /**
  * called via ajax to perform viz ajax task (defined by plugintask method)
  */
 public function display()
 {
     $document = JFactory::getDocument();
     $id = JRequest::getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = JRequest::getVar('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     } else {
         $task = JRequest::getVar('task');
         $path = JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/controllers/' . $viz->plugin . '.php';
         if (file_exists($path)) {
             require_once $path;
         } else {
             JError::raiseNotice(400, 'could not load viz:' . $viz->plugin);
             return;
         }
         $controllerName = 'FabrikControllerVisualization' . $viz->plugin;
         $controller = new $controllerName();
         $controller->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/views');
         $controller->addViewPath(COM_FABRIK_FRONTEND . '/views');
         //add the model path
         $modelpaths = JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
         $modelpaths = JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models');
         $origId = JRequest::getInt('visualizationid');
         JRequest::setVar('visualizationid', $id);
         $controller->{$task}();
     }
 }
Exemplo n.º 2
0
 public function store($updateNulls = false)
 {
     //we don't want these to be stored - generates an sql error
     unset($this->db_table_name);
     unset($this->connection_id);
     return parent::store($updateNulls);
 }
Exemplo n.º 3
0
 /**
  * Get the plugins data to bind to the form
  *
  * @return  array
  */
 protected function getData()
 {
     $type = $this->getState('type');
     if ($type === 'validationrule') {
         $item = FabTable::getInstance('Element', 'FabrikTable');
         $item->load($this->getState('id'));
     } else {
         $feModel = $this->getPluginModel();
         $item = $feModel->getTable();
     }
     $data = (array) json_decode($item->params);
     $data['plugin'] = $this->getState('plugin');
     $data['params'] = (array) JArrayHelper::getValue($data, 'params', array());
     $data['params']['plugins'] = $this->getState('plugin');
     $data['validationrule']['plugin'] = $this->getState('plugin');
     $c = $this->getState('c') + 1;
     // Add plugin published state, locations and events
     $state = (array) JArrayHelper::getValue($data, 'plugin_state');
     $locations = (array) JArrayHelper::getValue($data, 'plugin_locations');
     $events = (array) JArrayHelper::getValue($data, 'plugin_events');
     $data['params']['plugin_state'] = JArrayHelper::getValue($state, $c, 1);
     $data['plugin_locations'] = JArrayHelper::getValue($locations, $c);
     $data['plugin_events'] = JArrayHelper::getValue($events, $c);
     return $data;
 }
Exemplo n.º 4
0
 /**
  * Called via ajax to perform viz ajax task (defined by plugintask method)
  *
  * @param   boolean  $cachable   If true, the view output will be cached
  * @param   array    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return  JController  A JController object to support chaining.
  */
 public function display($cachable = false, $urlparams = false)
 {
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $input = $app->input;
     $id = $input->getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = $input->get('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     } else {
         $task = $input->get('task');
         $path = JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/controllers/' . $viz->plugin . '.php';
         if (file_exists($path)) {
             require_once $path;
         } else {
             throw new RuntimeException('Could not load visualization: ' . $viz->plugin);
         }
         $controllerName = 'FabrikControllerVisualization' . $viz->plugin;
         $controller = new $controllerName();
         $controller->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/views');
         $controller->addViewPath(COM_FABRIK_FRONTEND . '/views');
         // Add the model path
         $modelpaths = JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
         $modelpaths = JModelLegacy::addIncludePath(COM_FABRIK_FRONTEND . '/models');
         $origId = $input->getInt('visualizationid');
         $input->set('visualizationid', $id);
         $controller->{$task}();
     }
     return $this;
 }
Exemplo n.º 5
0
 function getVisualization()
 {
     if (!isset($this->_row)) {
         $this->_row = FabTable::getInstance('Visualization', 'FabrikTable');
         $this->_row->load($this->getState('id'));
     }
     return $this->_row;
 }
Exemplo n.º 6
0
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param	type	The table type to instantiate
  * @param	string	A prefix for the table class name. Optional.
  * @param	array	Configuration array for model. Optional.
  * @return	JTable	A database object
  * @since	1.6
  */
 public function getTable($type = 'Connection', $prefix = 'FabrikTable', $config = array())
 {
     // not sure if we should be loading JTable or FabTable here
     // issue with using Fabtable is that it will always load the cached verion of the cnn
     // which might cause issues when migrating from test to live sites???
     $config['dbo'] = FabriKWorker::getDbo(true);
     return FabTable::getInstance($type, $prefix, $config);
 }
Exemplo n.º 7
0
 /**
  * load the model from the element id
  * $param string $key
  * @param int $id
  */
 function getJoinFromKey($key, $id)
 {
     if (!isset($this->_join)) {
         $db =& JFactory::getDbo();
         $this->_join = FabTable::getInstance('join', 'FabrikTable');
         $this->_join->load(array($key => $id));
     }
     return $this->_join;
 }
Exemplo n.º 8
0
 /**
  * if loading via id then we want to get the view name and add the plugin view and model paths
  * @return string view name
  */
 protected function getViewName()
 {
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load(JRequest::getInt('id'));
     $viewName = $viz->plugin;
     $this->addViewPath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viewName . DS . 'views');
     JModel::addIncludePath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viewName . DS . 'models');
     return $viewName;
 }
Exemplo n.º 9
0
 /**
  * If loading via id then we want to get the view name and add the plugin view and model paths
  *
  * @return   string  view name
  */
 protected function getViewName()
 {
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($this->input->getInt('id'));
     $viewName = $viz->plugin;
     $this->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viewName . '/views');
     JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viewName . '/models');
     return $viewName;
 }
Exemplo n.º 10
0
 /**
  * Overloaded bind function
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function bind($src, $ignore = array())
 {
     if (isset($src['params']) && is_array($src['params'])) {
         $registry = new JRegistry();
         $registry->loadArray($src['params']);
         $src['params'] = (string) $registry;
     }
     return parent::bind($src, $ignore);
 }
Exemplo n.º 11
0
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param   string $type   The table type to instantiate
  * @param   string $prefix A prefix for the table class name. Optional.
  * @param   array  $config Configuration array for model. Optional.
  *
  * @return  JTable    A database object
  */
 public function getTable($type = 'List', $prefix = 'FabrikTable', $config = array())
 {
     $sig = $type . $prefix . implode('.', $config);
     if (!array_key_exists($sig, $this->tables)) {
         $config['dbo'] = FabrikWorker::getDbo(true);
         $this->tables[$sig] = FabTable::getInstance($type, $prefix, $config);
     }
     return $this->tables[$sig];
 }
Exemplo n.º 12
0
 /**
  * Get the db row
  *
  * @param   bool  $force  force reload
  *
  * @return  object
  */
 public function &getTable($force = false)
 {
     if (!$this->row || $force) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables');
         $row = FabTable::getInstance('Cron', 'FabrikTable');
         $row->load($this->row);
         $this->row = $row;
     }
     return $this->row;
 }
Exemplo n.º 13
0
 /**
  * Method to load and return a model object.
  *
  * @param   string  $name    The name of the view
  * @param   string  $prefix  The class prefix. Optional.
  * @param   array   $config  configuration
  *
  * @return	mixed	Model object or boolean false if failed
  */
 protected function _createTable($name, $prefix = 'Table', $config = array())
 {
     // Clean the model name
     $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     // Make sure we are returning a DBO object
     if (!array_key_exists('dbo', $config)) {
         $config['dbo'] = $this->getDbo();
     }
     return FabTable::getInstance($name, $prefix, $config);
 }
Exemplo n.º 14
0
 /**
  * If loading via id then we want to get the view name and add the plugin view and model paths
  *
  * @return   string  view name
  */
 protected function getViewName()
 {
     if (!isset($this->viewName)) {
         $item = FabTable::getInstance('Cron', 'FabrikTable');
         $item->load(JRequest::getInt('id'));
         $this->viewName = $item->plugin;
         $this->addViewPath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/views');
         $this->addModelPath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/models');
         JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/models');
     }
     return $this->viewName;
 }
Exemplo n.º 15
0
 public function run()
 {
     $db = FabrikWorker::getDbo(true);
     $cid = JRequest::getVar('cid', array(0), 'method', 'array');
     JArrayHelper::toInteger($cid);
     $cid = implode(',', $cid);
     $query = $db->getQuery(true);
     $query->select('*')->from('#__{package}_cron')->where('id IN (' . $cid . ')');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $adminListModel = JModel::getInstance('List', 'FabrikModel');
     //JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_fabrik'.DS.'models');
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     $c = 0;
     $log = FabTable::getInstance('Log', 'FabrikTable');
     foreach ($rows as $row) {
         //load in the plugin
         $rowParams = json_decode($row->params);
         $log->message = '';
         $log->id = null;
         $log->referring_url = '';
         $log->message_type = 'plg.cron.' . $row->plugin;
         $plugin =& $pluginManager->getPlugIn($row->plugin, 'cron');
         $table = FabTable::getInstance('cron', 'FabrikTable');
         $table->load($row->id);
         $plugin->setRow($table);
         $params =& $plugin->getParams();
         $thisListModel = clone $listModel;
         $thisAdminListModel = clone $adminListModel;
         $tid = (int) $rowParams->table;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             //. var_export($table);
             if ($plugin->requiresTableData()) {
                 $table =& $listModel->getTable();
                 $data = $thisListModel->getData();
                 $log->message .= "\n" . $thisListModel->_buildQuery();
             }
         } else {
             $data = array();
         }
         // $$$ hugh - added table model param, in case plugin wants to do further table processing
         $c = $c + $plugin->process($data, $thisListModel, $thisAdminListModel);
         if ($plugin->getParams()->get('log', 0) == 1) {
             $log->message = $plugin->getLog() . "\n\n" . $log->message;
             $log->store();
         }
     }
     $this->setRedirect('index.php?option=com_fabrik&view=crons', $c . " records updated");
 }
Exemplo n.º 16
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   hash named array
  * @param   array  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  null|string	 null is operation was satisfactory, otherwise returns an error
  */
 public function bind($array, $ignore = array())
 {
     // Bind the rules.
     if (isset($array['rules']) && is_array($array['rules'])) {
         $rules = new JAccessRules($array['rules']);
         $this->setRules($rules);
     }
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new JRegistry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
Exemplo n.º 17
0
 /**
  * called via ajax to perform viz ajax task (defined by plugintask method)
  */
 public function display()
 {
     $document = JFactory::getDocument();
     $id = JRequest::getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModel::addIncludePath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viz->plugin . DS . 'models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = JRequest::getVar('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     }
 }
Exemplo n.º 18
0
 /**
  * Method to bind an associative array or object to the JTable instance.This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function bind($src, $ignore = array())
 {
     // Bind the rules.
     if (isset($array['rules']) && is_array($array['rules'])) {
         $rules = new JAccessRules($array['rules']);
         $this->setRules($rules);
     }
     // Covert the params to a json object if its set as an array
     if (isset($src['params']) && is_array($src['params'])) {
         $registry = new JRegistry();
         $registry->loadArray($src['params']);
         $src['params'] = (string) $registry;
     }
     return parent::bind($src, $ignore);
 }
Exemplo n.º 19
0
	/**
	 * Display the view
	 */

	function display()
	{
		$document = JFactory::getDocument();

		$viewName = str_replace('FabrikControllerVisualization', '', get_class($this));
		if ($viewName == '') {
			// if we are using a url like http://localhost/fabrik3.0.x/index.php?option=com_fabrik&view=visualization&id=6
			// then we need to ascertain which viz to use
			$id = JRequest::getInt('id');
			$viz = FabTable::getInstance('Visualization', 'FabrikTable');

			$viz->load(JRequest::getInt('id'));
			$viewName = $viz->plugin;
			$this->addViewPath(JPATH_SITE.DS.'plugins'.DS.'fabrik_visualization'.DS.$viewName.DS.'views');
			//add the model path
			$modelpaths = JModel::addIncludePath(JPATH_SITE.DS.'plugins'.DS.'fabrik_visualization'.DS.$viewName.DS.'models');
		}
		$viewType	= $document->getType();

		// Set the default view name from the Request
		$view = $this->getView($viewName, $viewType);

		// Push a model into the view

		$model = $this->getModel($viewName);
		if (!JError::isError($model)) {
			$view->setModel($model, true);
		}
		// Display the view
		$view->assign('error', $this->getError());

		// f3 cache with raw view gives error
		if (in_array(JRequest::getCmd('format'), array('raw', 'csv'))) {
			$view->display();
		} else {
			$post = JRequest::get('post');
			//build unique cache id on url, post and user id
			$user = JFactory::getUser();
			$cacheid = serialize(array(JRequest::getURI(), $post, $user->get('id'), get_class($view), 'display', $this->cacheId));
			$cache = JFactory::getCache('com_fabrik', 'view');
			$cache->get($view, 'display', $cacheid);
		}
	}
Exemplo n.º 20
0
 /**
  * Get the plugins data to bind to the form
  *
  * @return  array
  */
 protected function getData()
 {
     $type = $this->getState('type');
     $data = array();
     if ($type === 'validationrule') {
         $item = FabTable::getInstance('Element', 'FabrikTable');
         $item->load($this->getState('id'));
     } elseif ($type === 'elementjavascript') {
         $item = FabTable::getInstance('Jsaction', 'FabrikTable');
         $item->load($this->getState('id'));
         $data = $item->getProperties();
     } else {
         $feModel = $this->getPluginModel();
         $item = $feModel->getTable();
     }
     $data = $data + (array) json_decode($item->params);
     $data['plugin'] = $this->getState('plugin');
     $data['params'] = (array) FArrayHelper::getValue($data, 'params', array());
     $data['params']['plugins'] = $this->getState('plugin');
     $data['validationrule']['plugin'] = $this->getState('plugin');
     $data['validationrule']['plugin_published'] = $this->getState('plugin_published');
     $data['validationrule']['show_icon'] = $this->getState('show_icon');
     $data['validationrule']['must_validate'] = $this->getState('must_validate');
     $data['validationrule']['validate_in'] = $this->getState('validate_in');
     $data['validationrule']['validation_on'] = $this->getState('validation_on');
     $c = $this->getState('c') + 1;
     // Add plugin published state, locations, descriptions and events
     $state = (array) FArrayHelper::getValue($data, 'plugin_state');
     $locations = (array) FArrayHelper::getValue($data, 'plugin_locations');
     $events = (array) FArrayHelper::getValue($data, 'plugin_events');
     $descriptions = (array) FArrayHelper::getValue($data, 'plugin_description');
     $data['params']['plugin_state'] = FArrayHelper::getValue($state, $c, 1);
     $data['plugin_locations'] = FArrayHelper::getValue($locations, $c);
     $data['plugin_events'] = FArrayHelper::getValue($events, $c);
     $data['plugin_description'] = FArrayHelper::getValue($descriptions, $c);
     // For list plugins view
     $data['params']['plugin_description'] = FArrayHelper::getValue($descriptions, $c);
     return $data;
 }
Exemplo n.º 21
0
 /**
  * Alter the forms' data collection table when the forms' groups and/or
  * elements are altered
  *
  * @return void|JError
  */
 public function ammendTable()
 {
     $db = FabrikWorker::getDbo(true);
     $input = $this->app->input;
     $query = $db->getQuery(true);
     $table = $this->table;
     $amend = false;
     $tableName = $table->db_table_name;
     $fabrikDb = $this->getDb();
     $columns = $fabrikDb->getTableColumns($tableName);
     $existingFields = array_keys($columns);
     $existingFields = array_map('strtolower', $existingFields);
     $lastField = empty($existingFields) ? '' : $existingFields[count($existingFields) - 1];
     $sql = 'ALTER TABLE ' . $db->qn($tableName) . ' ';
     $sqlAdd = array();
     // $$$ hugh - looks like this is now an array in jform
     $jForm = $input->get('jform', array(), 'array');
     $arGroups = FArrayHelper::getValue($jForm, 'current_groups', array(), 'array');
     if (empty($arGroups)) {
         // Get a list of groups used by the form
         $query->select('group_id')->from('#__{package}_formgroup')->where('form_id = ' . (int) $this->getFormModel()->getId());
         $db->setQuery($query);
         $groups = $db->loadObjectList();
         $arGroups = array();
         foreach ($groups as $g) {
             $arGroups[] = $g->group_id;
         }
     }
     $arAddedObj = array();
     foreach ($arGroups as $group_id) {
         $group = FabTable::getInstance('Group', 'FabrikTable');
         $group->load($group_id);
         if ($group->is_join == '0') {
             $query->clear();
             $query->select('*')->from('#__{package}_elements')->where('group_id = ' . (int) $group_id);
             $db->setQuery($query);
             $elements = $db->loadObjectList();
             foreach ($elements as $obj) {
                 $objName = $obj->name;
                 /*
                  * Do the check in lowercase (we already strtowlower()'ed $existingFields up there ^^,
                  * because MySQL field names are case insensitive, so if the element is called 'foo' and there
                  * is a column called 'Foo', and we try and create 'foo' on the table ... it'll blow up.
                  *
                  * However, leave the $objName unchanged, so if we do create a column for it, it uses the case
                  * they specific in the element name - it's not up to us to force their column naming to all lower,
                  * we just need to avoid clashes.
                  *
                  * @TODO We might consider detecting and raising a warning about case inconsistencies?
                  */
                 if (!in_array(strtolower($objName), $existingFields)) {
                     // Make sure that the object is not already in the table
                     if (!in_array($objName, $arAddedObj)) {
                         // Any elements that are names the same (eg radio buttons) can not be entered twice into the database
                         $arAddedObj[] = $objName;
                         $pluginClassName = $obj->plugin;
                         $plugin = $this->pluginManager->getPlugIn($pluginClassName, 'element');
                         if (is_object($plugin)) {
                             $plugin->setId($obj->id);
                             $objType = $plugin->getFieldDescription();
                         } else {
                             $objType = 'VARCHAR(255)';
                         }
                         if ($objName != '' && !is_null($objType)) {
                             $amend = true;
                             $add = 'ADD COLUMN ' . $db->qn($objName) . ' ' . $objType . ' null';
                             if ($lastField !== '') {
                                 $add .= ' AFTER ' . $db->qn($lastField);
                             }
                             $sqlAdd[] = $add;
                         }
                     }
                 }
             }
         }
     }
     if ($amend) {
         $sql .= implode(', ', $sqlAdd);
         $fabrikDb->setQuery($sql);
         try {
             $fabrikDb->execute();
         } catch (Exception $e) {
             JError::raiseWarning(500, 'amend table: ' . $e->getMessage());
         }
     }
 }
Exemplo n.º 22
0
 /**
  * Run the selected cron plugins
  *
  * @return  void
  */
 public function run()
 {
     $mailer = JFactory::getMailer();
     $config = JFactory::getConfig();
     $db = FabrikWorker::getDbo(true);
     $app = JFactory::getApplication();
     $input = $app->input;
     $cid = $input->get('cid', array(), 'array');
     JArrayHelper::toInteger($cid);
     $cid = implode(',', $cid);
     $query = $db->getQuery(true);
     $query->select('*')->from('#__{package}_cron')->where('id IN (' . $cid . ')');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $adminListModel = JModelLegacy::getInstance('List', 'FabrikAdminModel');
     $pluginManager = JModelLegacy::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
     $c = 0;
     $this->log = FabTable::getInstance('Log', 'FabrikTable');
     register_shutdown_function(array($this, 'shutdownHandler'));
     foreach ($rows as $row) {
         // Load in the plugin
         $rowParams = json_decode($row->params);
         $this->log->message = '';
         $this->log->id = null;
         $this->log->referring_url = '';
         $this->log->message_type = 'plg.cron.' . $row->plugin;
         $plugin = $pluginManager->getPlugIn($row->plugin, 'cron');
         $table = FabTable::getInstance('cron', 'FabrikTable');
         $table->load($row->id);
         $plugin->setRow($table);
         $plugin->getParams();
         $thisListModel = clone $listModel;
         $thisAdminListModel = clone $adminListModel;
         $tid = (int) $rowParams->table;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $this->log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             if ($plugin->requiresTableData()) {
                 $thisListModel->setLimits(0, 0);
                 $thisListModel->getPagination(0, 0, 0);
                 $data = $thisListModel->getData();
             }
         } else {
             $data = array();
         }
         $this->runningId = $row->id;
         // $$$ hugh - added table model param, in case plugin wants to do further table processing
         $c = $c + $plugin->process($data, $thisListModel, $thisAdminListModel);
         $this->log->message = $plugin->getLog() . "\n\n" . $this->log->message;
         if ($plugin->getParams()->get('log', 0) == 1) {
             $this->log->store();
         }
         // Email log message
         $recipient = $plugin->getParams()->get('log_email', '');
         if ($recipient != '') {
             $recipient = explode(',', $recipient);
             $subject = $config->get('sitename') . ': ' . $row->plugin . ' scheduled task';
             $mailer->sendMail($config->get('mailfrom'), $config->get('fromname'), $recipient, $subject, $this->log->message, true);
         }
     }
     $this->setRedirect('index.php?option=com_fabrik&view=crons', $c . ' records updated');
 }
Exemplo n.º 23
0
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param   type    $type    The table type to instantiate
  * @param   string  $prefix  A prefix for the table class name. Optional.
  * @param   array   $config  Configuration array for model. Optional.
  *
  * @return  JTable	A database object
  */
 public function getTable($type = 'Group', $prefix = 'FabrikTable', $config = array())
 {
     $config['dbo'] = FabrikWorker::getDbo();
     return FabTable::getInstance($type, $prefix, $config);
 }
Exemplo n.º 24
0
 /**
  * Get the item
  *
  * @return  FabrikTableVisualization
  */
 public function getVisualization()
 {
     if (!isset($this->row)) {
         $this->row = FabTable::getInstance('Visualization', 'FabrikTable');
         $this->row->load($this->getState('id'));
         $this->setListIds();
         // Needed to load the language file!
         $pluginManager = FabrikWorker::getPluginManager();
         $plugin = $pluginManager->getPlugIn($this->_row->plugin, 'visualization');
     }
     return $this->row;
 }
Exemplo n.º 25
0
 /**
  * log  to table jos_fabrik_logs
  * @param string $type e.g. 'fabrik.fileupload.download'
  * @param mixed $msg array/object/string
  * @param bool $jsonEncode
  */
 public function log($type, $msg, $jsonEncode = true)
 {
     if ($jsonEncode) {
         $msg = json_encode($msg);
     }
     $log = FabTable::getInstance('log', 'FabrikTable');
     $log->message_type = $type;
     $log->message = $msg;
     $log->store();
 }
Exemplo n.º 26
0
 /**
  * Load the default connection
  *
  * @return  object  default connection
  */
 function &loadDefaultConnection()
 {
     if (!$this->_defaultConnection) {
         // $$$ rob connections are pooled for all packages - each package should use
         // jos_fabrik_connections and not jos_{package}_connections
         $row = FabTable::getInstance('Connection', 'FabrikTable');
         $row->load(array('default' => 1));
         $this->_defaultConnection = $row;
     }
     $this->_connection = $this->_defaultConnection;
     return $this->_defaultConnection;
 }
Exemplo n.º 27
0
 /**
  * create the SQL install file
  *
  * @param   object  $row  package
  *
  * @return  string  path
  */
 protected function makeInstallSQL($row)
 {
     $sql = '';
     $config = JFactory::getConfig();
     $db = FabrikWorker::getDbo(true);
     // Create the sql for the cloned fabrik meta data tables
     foreach ($this->tables as $table) {
         $db->setQuery('SHOW CREATE TABLE ' . $table);
         $tbl = $db->loadRow();
         $tbl = str_replace('_fabrik_', '_' . $row->component_name . '_', $tbl[1]);
         $tbl = str_replace($config->get('dbprefix'), '#__', $tbl);
         $sql .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $tbl) . ";\n\n";
         $table = str_replace(array('_fabrik_', '{package}'), array('_' . $row->component_name . '_', $row->component_name), $table);
         $sql .= 'TRUNCATE TABLE ' . $table . ";\n\n";
     }
     foreach ($row->blocks as $block => $ids) {
         $key = FabrikString::rtrimword($block, 's');
     }
     // Create the sql to build the db tables that store the data.
     $formModel = JModelLegacy::getInstance('form', 'FabrikFEModel');
     $lookups = $this->getInstallItems($row);
     $lids = $lookups->list;
     JArrayHelper::toInteger($lids);
     $plugins = array();
     foreach ($lids as $lid) {
         $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
         $listModel->setId($lid);
         $sql .= "\n\n" . $listModel->getCreateTableSQL(true);
     }
     foreach ($lookups->form as $fid) {
         $formModel->setId($fid);
         if (!in_array($fid, $lookups->list)) {
             $lookups->list[] = $fid;
         }
         // @FIXME get sql to create tables for dbjoin/cdd elements (need to do if not exists)
         $dbs = $formModel->getElementOptions(false, 'name', true, true, array());
     }
     $sql .= "\n\n";
     if (isset($lookups->visualization)) {
         $vrow = FabTable::getInstance('Visualization', 'FabrikTable');
         $vrow->load($vid);
         $visModel = JModelLegacy::getInstance($vrow->plugin, 'fabrikModel');
         $visModel->setId($vid);
         $listModels = $visModel->getlistModels();
         foreach ($listModels as $lmodel) {
             $vrow = FabTable::getInstance('Visualization', 'FabrikTable');
             $vrow->load($vid);
             $visModel = JModel::getInstance($vrow->plugin, 'fabrikModel');
             $visModel->setId($vid);
             $listModels = $visModel->getlistModels();
             foreach ($listModels as $lmodel) {
                 $sql .= $lmodel->getCreateTableSQL(true);
                 // Add the table ids to the $lookups->list
                 if (!in_array($lmodel->getId(), $lookups->list)) {
                     $lookups->list[] = $lmodel->getId();
                 }
             }
         }
     }
     $path = $this->outputPath . 'admin/sql/install.mysql.uft8.sql';
     JFile::write($path, $sql);
     return $path;
 }
Exemplo n.º 28
0
 /**
  * Construct
  *
  * @param   object  &$db  database object
  */
 public function __construct(&$db)
 {
     parent::__construct('#__{package}_joins', 'id', $db);
 }
Exemplo n.º 29
0
 /**
  * Run all active cron jobs
  *
  * @return void
  */
 protected function doCron()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin() || JRequest::getVar('option') == 'com_acymailing') {
         return;
     }
     // $$$ hugh - don't want to run on things like AJAX calls
     if (JRequest::getVar('format', '') == 'raw') {
         return;
     }
     // Get all active tasks
     $db = FabrikWorker::getDbo(true);
     $now = JRequest::getVar('fabrikcron_run', false);
     $log = FabTable::getInstance('Log', 'FabrikTable');
     if (!$now) {
         /* $$$ hugh - changed from using NOW() to JFactory::getDate(), to avoid time zone issues, see:
          * http://fabrikar.com/forums/showthread.php?p=102245#post102245
          * .. which seems reasonable, as we use getDate() to set 'lastrun' to at the end of this func
          */
         $nextrun = "CASE " . "WHEN unit = 'second' THEN DATE_ADD( lastrun, INTERVAL frequency SECOND )\n" . "WHEN unit = 'minute' THEN DATE_ADD( lastrun, INTERVAL frequency MINUTE )\n" . "WHEN unit = 'hour' THEN DATE_ADD( lastrun, INTERVAL frequency HOUR )\n" . "WHEN unit = 'day' THEN DATE_ADD( lastrun, INTERVAL frequency DAY )\n" . "WHEN unit = 'week' THEN DATE_ADD( lastrun, INTERVAL frequency WEEK )\n" . "WHEN unit = 'month' THEN DATE_ADD( lastrun, INTERVAL frequency MONTH )\n" . "WHEN unit = 'year' THEN DATE_ADD( lastrun, INTERVAL frequency YEAR ) END";
         $query = "SELECT id, plugin, lastrun, unit, frequency, {$nextrun} AS nextrun FROM #__{package}_cron\n";
         $query .= "WHERE published = '1' ";
         $query .= "AND {$nextrun} < '" . JFactory::getDate()->toSql() . "'";
     } else {
         $query = "SELECT id, plugin FROM #__{package}_cron WHERE published = '1'";
     }
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (empty($rows)) {
         return;
     }
     $log->message = '';
     /* $$$ hugh - set 'state' to 2 for selected rows, so we don't end up running
      * multiple copies, if this code is run again before selected plugins have
      * finished running, see:
      * http://fabrikar.com/forums/showthread.php?p=114008#post114008
      */
     $ids = array();
     foreach ($rows as $row) {
         $ids[] = (int) $row->id;
     }
     $query = $db->getQuery(true);
     $query->update('#__{package}_cron')->set('published = 2')->where('id IN (' . implode(',', $ids) . ')');
     $db->setQuery($query);
     $db->query();
     JModel::addIncludePath(JPATH_SITE . '/components/com_fabrik/models');
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     foreach ($rows as $row) {
         $log->message = '';
         $log->id = null;
         $log->referring_url = '';
         // Load in the plugin
         $plugin = $pluginManager->getPluginFromId($row->id, 'Cron');
         $log->message_type = 'plg.cron.' . $row->plugin;
         if (!$plugin->queryStringActivated()) {
             // $$$ hugh - don't forget to make it runnable again before continuing
             $query->clear();
             $query->update('#__{package}_cron')->set('published = 1')->where('id = ' . $row->id);
             $db->setQuery($query);
             $db->query();
             continue;
         }
         $tid = (int) $plugin->getParams()->get('table');
         $thisListModel = clone $listModel;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             if ($plugin->requiresTableData()) {
                 $table = $thisListModel->getTable();
                 $total = $thisListModel->getTotalRecords();
                 $nav = $thisListModel->getPagination($total, 0, $total);
                 $data = $thisListModel->getData();
                 $log->message .= "\n" . $thisListModel->_buildQuery();
             }
         } else {
             $data = array();
         }
         $res = $plugin->process($data, $thisListModel);
         $log->message = $plugin->getLog() . "\n\n" . $log->message;
         $now = JFactory::getDate();
         $now = $now->toUnix();
         $new = JFactory::getDate($row->nextrun);
         $tmp = $new->toUnix();
         switch ($row->unit) {
             case 'second':
                 $inc = 1;
                 break;
             case 'minute':
                 $inc = 60;
                 break;
             case 'hour':
                 $inc = 60 * 60;
                 break;
             default:
             case 'day':
                 $inc = 60 * 60 * 24;
                 break;
         }
         /* Don't use NOW() as the last run date as this could mean that the cron
          * jobs aren't run as frequently as specified
          * if the lastrun date was set in admin to ages ago, then incrementally increase the
          * last run date until it is less than now
          */
         while ($tmp + $inc * $row->frequency < $now) {
             $tmp = $tmp + $inc * $row->frequency;
         }
         // Mark them as being run
         // $$$ hugh - and make it runnable again by setting 'state' back to 1
         $nextrun = JFactory::getDate($tmp);
         $query->clear();
         $query->update('#__{package}_cron')->set('published = 1, lastrun = ' . $db->quote($nextrun->toSql()))->where('id = ' . $row->id);
         $db->setQuery($query);
         $db->query();
         // Log if asked for
         if ($plugin->getParams()->get('log', 0) == 1) {
             $log->store();
         }
     }
 }
Exemplo n.º 30
0
 function store()
 {
     unset($this->join_id);
     return parent::store();
 }