Пример #1
0
 /**
  * Returns report schedule properties
  *
  * @param string $id Report schedule ID
  *
  * @return array
  */
 public function getInfo($id)
 {
     $query = "SELECT report_id, next_run, time_interval\n        FROM {$this->table_name}\n        WHERE id = " . $this->db->quoted($id);
     $result = $this->db->query($query);
     $row = $this->db->fetchByAssoc($result);
     $row = $this->fromConvertReportScheduleDBRow($row);
     return $row;
 }
Пример #2
0
 /**
  * Returns where clause for active users
  *
  * @param string $alias for user table
  * @return string
  */
 protected function getActiveUsersWhere($alias = 'users')
 {
     $aliasQuery = '';
     if (!empty($alias)) {
         $aliasQuery = $alias . '.';
     }
     $query = sprintf(' ' . $aliasQuery . 'status = %s AND ' . $aliasQuery . 'is_group = 0 AND ' . $aliasQuery . 'portal_only = 0 AND %s', $this->db->quoted('Active'), $this->getExcludeSystemUsersWhere($alias));
     return $query;
 }
Пример #3
0
 /**
  * Builds main join for archived emails
  * @param string $params
  * @return string JOIN clause
  */
 protected function getEmailsJoin($params = array())
 {
     $bean_id = $this->db->quoted($this->focus->id);
     if (!empty($params['join_table_alias'])) {
         $table_name = $params['join_table_alias'];
     } else {
         $table_name = 'emails';
     }
     return "INNER JOIN (\n" . "select eb.email_id FROM emails_beans eb where eb.bean_module = '{$this->focus->module_dir}'\n                AND eb.bean_id = {$bean_id} AND eb.deleted=0\n" . " UNION " . "select DISTINCT eear.email_id  from emails_email_addr_rel eear INNER JOIN email_addr_bean_rel eabr\n            ON eabr.bean_id = {$bean_id} AND eabr.bean_module = '{$this->focus->module_dir}' AND\n            eabr.email_address_id = eear.email_address_id and eabr.deleted=0 where eear.deleted=0\n" . ") email_ids ON {$table_name}.id=email_ids.email_id ";
 }
Пример #4
0
 /**
  * Remove old jobs that still are marked as running
  * @return bool true if no failed job discovered, false if some job were failed
  */
 public function cleanup()
 {
     // fail jobs that are too old
     $ret = true;
     $date = $this->db->convert($this->db->quoted($GLOBALS['timedate']->getNow()->modify("+{$this->timeout} seconds")->asDb()), 'datetime');
     $res = $this->db->query("SELECT id FROM {$this->job_queue_table} WHERE status='" . SchedulersJob::JOB_STATUS_RUNNING . "' AND date_modified <= {$date}");
     while ($row = $this->db->fetchByAssoc($res)) {
         $this->resolveJob($row["id"], SchedulersJob::JOB_FAILURE, translate('ERR_TIMEOUT', 'SchedulersJobs'));
         $ret = false;
     }
     // TODO: soft-delete old done jobs?
     return $ret;
 }
Пример #5
0
 /**
  * Construct where clause from a list of name-value pairs.
  * @param array $fields_array Name/value pairs for column checks
  * @return string The WHERE clause
  */
 function get_where($fields_array)
 {
     $where_clause = "";
     foreach ($fields_array as $name => $value) {
         if (!empty($where_clause)) {
             $where_clause .= " AND ";
         }
         $name = $this->db->getValidDBName($name);
         $where_clause .= "{$name} = " . $this->db->quoted($value, false);
     }
     if (!empty($where_clause)) {
         return "WHERE {$where_clause} AND deleted=0";
     } else {
         return "WHERE deleted=0";
     }
 }
Пример #6
0
 /**
  * Retrieve current user
  * @return User
  */
 protected function getUser()
 {
     $user = BeanFactory::getBean('Users');
     $user_id = $this->db->getOne("select id from users where deleted=0 AND user_name = " . $this->db->quoted($this->context['admin']), false);
     // Disable logic hooks.
     $user->processed = true;
     $user->retrieve($user_id);
     return $user;
 }
Пример #7
0
 public function migrateToOpportunities()
 {
     $sq = new SugarQuery();
     $sq->select(array('id', 'content'));
     $sq->from(BeanFactory::getBean('Reports'), array('team_security' => false));
     $sq->where()->equals('module', 'Opportunities')->contains('content', '"name":"sales_stage"');
     $results = $sq->execute('array', false);
     $fixedReports = array();
     // since we are dealing with json data, don't have fetchByAssoc encode the data
     foreach ($results as $row) {
         // reset the name, just in case.
         $this->rli_table_name = 'Opportunities:revenuelineitems';
         $report = json_decode($row['content'], true);
         // if links_defs is there, we need to unset it from there
         if (isset($report['links_def'])) {
             if ($loc = array_search('revenuelineitems', $report['links_def'])) {
                 unset($report['links_def'][$loc]);
             }
             // if we are setting the links_defs, the rli_table_name needs to be changed
             $this->rli_table_name = 'revenuelineitems';
         } elseif (isset($report['full_table_list'])) {
             if (isset($report['full_table_list']['self']['children']) && is_array($report['full_table_list']['self']['children'])) {
                 // find the RLI module
                 foreach ($report['full_table_list']['self']['children'] as $child) {
                     if (isset($report['full_table_list'][$child]['module']) && $report['full_table_list'][$child]['module'] === 'RevenueLineItems') {
                         $this->rli_table_name = $child;
                         break;
                     }
                 }
                 unset($report['full_table_list']['self']['children'][$this->rli_table_name]);
             }
             // if it's in the full_table_list, it should be removed from there.
             if (isset($report['full_table_list'][$this->rli_table_name])) {
                 unset($report['full_table_list'][$this->rli_table_name]);
             }
         } else {
             // if we don't have a links_def or the full_table_list, we should just bail out now.
             continue;
         }
         // lets loop though all the display_columns and find anyone that is sales_stage
         foreach (array('group_defs', 'display_columns', 'summary_columns') as $type) {
             foreach ($report[$type] as $key => $column) {
                 if ($column['name'] == 'sales_stage' && $column['table_key'] == $this->rli_table_name) {
                     $report[$type][$key]['table_key'] = 'self';
                 }
             }
         }
         // now lets fix all the filters.
         foreach ($report['filters_def'] as $name => $filter) {
             $returnSingleFilter = false;
             if (isset($filter['name']) && isset($filter['table_key'])) {
                 $returnSingleFilter = true;
                 $filter = array($filter);
             }
             $filter = $this->fixFilters($filter, 'self');
             if ($returnSingleFilter) {
                 $filter = array_shift($filter);
             }
             $report['filters_def'][$name] = $filter;
         }
         $json_def = json_encode($report, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
         $fixedReports[] = $json_def;
         $sql = 'UPDATE saved_reports
                 SET content = ' . $this->db->quoted($json_def) . '
                 WHERE id = ' . $this->db->quoted($row['id']);
         $this->db->query($sql);
         $this->cleanUp();
     }
     return $fixedReports;
 }