Load logs from DB.

@author Vova Feldman (@svovaf)
@since  1.2.1.6

@param bool   $filters
@param string $filename
@param int    $limit
@param int    $offset
@param bool   $order

@return false|string File download URL or false on failure.
769867
public static function download_db_logs(
			$filters = false,
			$filename = '',
			$limit = 10000,
			$offset = 0,
			$order = false
		) {
			global $wpdb;

			$query = self::build_db_logs_query(
				$filters,
				$limit,
				$offset,
				$order,
				true
			);

			$upload_dir = wp_upload_dir();
			if ( empty( $filename ) ) {
				$filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
			}
			$filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";

			$query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";

			$columns = '';
			for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
				if ( $i > 0 ) {
					$columns .= ', ';
				}

				$columns .= "'" . self::$_log_columns[ $i ] . "'";
			}

			$query = "SELECT {$columns} UNION ALL " . $query;

			$result = $wpdb->query( $query );

			if ( false === $result ) {
				return false;
			}

			return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
		}
212066
private static function build_db_logs_query(
			$filters = false,
			$limit = 200,
			$offset = 0,
			$order = false,
			$escape_eol = false
		) {
			global $wpdb;

			$select = '*';

			if ( $escape_eol ) {
				$select = '';
				for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
					if ( $i > 0 ) {
						$select .= ', ';
					}

					if ( 'message' !== self::$_log_columns[ $i ] ) {
						$select .= self::$_log_columns[ $i ];
					} else {
						$select .= 'REPLACE(message , \'\n\', \' \') AS message';
					}
				}
			}

			$query = "SELECT {$select} FROM {$wpdb->prefix}fs_logger";
			if ( is_array( $filters ) ) {
				$criteria = array();

				if ( ! empty( $filters['type'] ) && 'all' !== $filters['type'] ) {
					$filters['type'] = strtolower( $filters['type'] );

					switch ( $filters['type'] ) {
						case 'warn_error':
							$criteria[] = array( 'col' => 'type', 'val' => array( 'warn', 'error' ) );
							break;
						case 'error':
						case 'warn':
							$criteria[] = array( 'col' => 'type', 'val' => $filters['type'] );
							break;
						case 'info':
						default:
							$criteria[] = array( 'col' => 'type', 'val' => array( 'info', 'log' ) );
							break;
					}
				}

				if ( ! empty( $filters['request_type'] ) ) {
					$filters['request_type'] = strtolower( $filters['request_type'] );

					if ( in_array( $filters['request_type'], array( 'call', 'ajax', 'cron' ) ) ) {
						$criteria[] = array( 'col' => 'request_type', 'val' => $filters['request_type'] );
					}
				}

				if ( ! empty( $filters['file'] ) ) {
					$criteria[] = array(
						'col' => 'file',
						'op'  => 'LIKE',
						'val' => '%' . esc_sql( $filters['file'] ),
					);
				}

				if ( ! empty( $filters['function'] ) ) {
					$criteria[] = array(
						'col' => 'function',
						'op'  => 'LIKE',
						'val' => '%' . esc_sql( $filters['function'] ),
					);
				}

				if ( ! empty( $filters['process_id'] ) && is_numeric( $filters['process_id'] ) ) {
					$criteria[] = array( 'col' => 'process_id', 'val' => $filters['process_id'] );
				}

				if ( ! empty( $filters['logger'] ) ) {
					$criteria[] = array(
						'col' => 'logger',
						'op'  => 'LIKE',
						'val' => '%' . esc_sql( $filters['logger'] ) . '%',
					);
				}

				if ( ! empty( $filters['message'] ) ) {
					$criteria[] = array(
						'col' => 'message',
						'op'  => 'LIKE',
						'val' => '%' . esc_sql( $filters['message'] ) . '%',
					);
				}

				if ( 0 < count( $criteria ) ) {
					$query .= "\nWHERE\n";

					$first = true;
					foreach ( $criteria as $c ) {
						if ( ! $first ) {
							$query .= "AND\n";
						}

						if ( is_array( $c['val'] ) ) {
							$operator = 'IN';

							for ( $i = 0, $len = count( $c['val'] ); $i < $len; $i ++ ) {
								$c['val'][ $i ] = "'" . esc_sql( $c['val'][ $i ] ) . "'";
							}

							$val = '(' . implode( ',', $c['val'] ) . ')';
						} else {
							$operator = ! empty( $c['op'] ) ? $c['op'] : '=';
							$val      = "'" . esc_sql( $c['val'] ) . "'";
						}

						$query .= "`{$c['col']}` {$operator} {$val}\n";

						$first = false;
					}
				}
			}

			if ( ! is_array( $order ) ) {
				$order = array(
					'col'   => 'id',
					'order' => 'desc'
				);
			}

			$query .= " ORDER BY {$order['col']} {$order['order']} LIMIT {$offset},{$limit}";

			return $query;
		}
688191
public function get( $first = TRUE, $orders = array(), $limits = array() ){
		$this->validateFocus();
		$data = array();
		$conditions	= $this->getConditionQuery( array(), TRUE, TRUE, FALSE );						//  render WHERE clause if needed, cursored, without functions
		$orders		= $this->getOrderCondition( $orders );
		$limits		= $this->getLimitCondition( $limits );
		$columns	= $this->getColumnEnumeration( $this->columns );								//  get enumeration of masked column names
		$query		= 'SELECT '.$columns.' FROM '.$this->getTableName().' WHERE '.$conditions.$orders.$limits;

		$resultSet	= $this->dbc->query( $query );
		if( !$resultSet )
			return $first ? NULL : array();
		$resultList	= $resultSet->fetchAll( $this->getFetchMode() );
		if( $first )
			return $resultList ? $resultList[0] : NULL;
		return $resultList;
	}
740928
public function getSearchRequest($filter, $limit = 1, $conditions = [])
    {
        
        return $this->sourceDataAdapter->getSearchRequest($filter, $limit, $conditions);
    }
1242178
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $query = $this->createQueryBuilder($criteria, $orderBy, $limit, $offset);
        return $this->getResultFromQueryBuilder($query);
    }
143320
public function findBy(array $where, array $orderBy = null, $limit = null, $offset = null)
    {
        return $this->getRepository()->findBy($where, $orderBy, $limit, $offset);
    }
694176
public function listFilesInFolder($folder, array $filter = null, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);
		$response = $this->getFileUploadFolder($folder);
		if($response->error->exist){
			return $response;
		}
		$folder = $response->result->set;
        $filter[] = array(
            'glue' => ' and',
            'condition' => array(
                'column' => $this->entity['f']['alias'] . '.file_upload_folder',
                'comparison' => '=',
                'value' => $folder->getId())
        );
        $response = $this->listFiles($filter, $sortOrder, $limit);

		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
    }
700778
public function getFirstRecord($filter = '', $order = ['.id'], $page = 1, $count = null, $dataDimensions = null)
    {
        $records = $this->getRecords($filter, $order, $page, $count, $dataDimensions);
        if ($records) {
            return array_shift($records);
        }

        return false;
    }
395295
public static function read( $fileName, $reverse = FALSE, $limit = 0 )
	{
		$data	= array();
		if( !file_exists( $fileName ) )
			throw new Exception( 'Log File "'.$fileName.'" is not existing.' );
		$lines		= file( $fileName );
		foreach( $lines as $line )
		{
			$line	= trim( $line );
			if( !$line )
				continue;
			$data[]	= json_decode( $line, TRUE );
		}
		if( $reverse )
			$data	= array_reverse( $data );
		if( $limit )
			$data	= array_slice( $data, 0, $limit );
		return $data;
	}
224439
public function loadFromFile($FileName)
    {
        if (! empty($FileName)) {
            $this->FileName = $FileName;
            $result = $this->_openSHPFile();
        } else {
            /* We operate on buffer emulated by readSHP / eofSHP */
            $result = true;
        }

        if ($result && ($this->_openDBFFile())) {
            if (! $this->_loadHeaders()) {
                $this->_closeSHPFile();
                $this->_closeDBFFile();

                return false;
            }
            if (! $this->_loadRecords()) {
                $this->_closeSHPFile();
                $this->_closeDBFFile();

                return false;
            }
            $this->_closeSHPFile();
            $this->_closeDBFFile();

            return true;
        }

        return false;
    }
1006194
public function findAllWithPagination($filters, $limit, $offset, $resultInArray = FALSE)
    {
        $where = $this->getQueryFilter($filters);
        $query = $this->getEntityManager()->createQuery('SELECT m FROM FulgurioLightCMSBundle:Media m ' . $where . ' ORDER BY m.created_at DESC')->setMaxResults($limit)->setFirstResult($offset);
        if (!empty($filters))
        {
            foreach ($filters as $filterKey => $filterValue)
            {
                $query->setParameter($filterKey, $filterValue);
            }
        }
        if ($resultInArray)
        {
            return $query->getArrayResult();
        }
        return $query->getResult();
    }
140985
public function getData( $first = FALSE, $orders = array(), $limit = array(), $verbose = FALSE )
	{
		$data = array();
		if( $this->isFocused() && sizeof( $this->fields ) )
		{
			$conditions	= $this->getConditionQuery( array() );
			$orders		= $this->getOrderQuery( $orders );
			$limit		= $this->getLimitQuery( $limit );

		 	$query = 'SELECT * FROM '.$this->getTableName().' WHERE '.$conditions.$orders.$limit;
			if( $verbose )
				echo '<br/>'.$query;
			$q	= $this->dbc->Execute( $query );
			if( $q->RecordCount() )
			{
				while( $d = $q->FetchNextObject( FALSE ) )
				{
					$line = array();
					foreach( $this->fields as $field )
						$line[$field] = $d->$field;
					$data[] = $line;
				}
			}
		}
		if( count( $data ) && $first )
			$data	= $data[0];
		return $data;
	}
1075601
public function findContentsByClassname($classnameArr = array(), $orderInfos = array(), $limitInfos = array())
    {
        $result = array();
        if (!is_array($classnameArr)) {
            return $result;
        }
        $db = $this->_em->getConnection();

        $start = (is_array($limitInfos) && array_key_exists('start', $limitInfos)) ? (int) $limitInfos['start'] : 0;
        $limit = (is_array($limitInfos) && array_key_exists('limit', $limitInfos)) ? (int) $limitInfos['limit'] : 0;
        $stmt = $db->executeQuery('SELECT * FROM `content` WHERE `classname` IN (?) order by modified desc limit ?,?', array($classnameArr, $start, $limit), array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY, 1, 1)
        );

        $items = $stmt->fetchAll();
        if ($items) {
            foreach ($items as $item) {
                $content = $this->_em->find(AbstractClassContent::getFullClassname($item['classname']), $item['uid']);
                if ($content) {
                    $result[] = $content;
                }
            }
        }

        return $result;
    }
344246
public function search(string $term, int $limit = null, array $filters = [])
    {
        $filters_array = [];

        if ($filters) {
            $filters_array = [
                'filters' => $this->resolveFilters(__FUNCTION__, $filters),
            ];
        }

        $data = [
            'term' => $term,
            'limit' => $limit,
            'filters' => $filters,
        ];

        $data = array_merge($data, $filters_array);

        $url = self::$base_url.'/search?'.http_build_query($data);

        return self::$curl->get($url);
    }
791159
public function limit($limit = null, $offset = null)
    {
        $this->results = $this->fetch($limit, $offset);

        return $this->results->fetchAll();
    }
1050506
public function download($query, $filename)
    {
        $this->query      = $query;
        $this->modelClass = get_class($query->getModel());

        $temporary = $this->generateExport();

        if ( ! $temporary) {
            return false;
        }

        return response()->download($temporary, $filename)->deleteFileAfterSend(true);
    }
47142
public function read ($limit = 0, $query = NULL, $view = NULL, $sort = NULL, $options = NULL) {
		return $this->api->read($this->list_name, $limit, $query, $view, $sort, $options);
	}