Improve empty feeds detection
This commit is contained in:
parent
5fc8ec2839
commit
69a37f02d7
13
index.php
13
index.php
@ -345,10 +345,19 @@ Router\get_action('refresh-all', function() {
|
||||
Router\get_action('feeds', function() {
|
||||
|
||||
$empty_feeds = Model\get_empty_feeds();
|
||||
if (count($empty_feeds) > 0) {
|
||||
$message = t('The following feeds are empty, there may be an error : ') . implode(', ', $empty_feeds);
|
||||
|
||||
if (! empty($empty_feeds)) {
|
||||
|
||||
$listing = array();
|
||||
|
||||
foreach ($empty_feeds as &$feed) {
|
||||
$listing[] = '"'.$feed['title'].'"';
|
||||
}
|
||||
|
||||
$message = t('The following feeds are empty, there is maybe an error: %s', implode(', ', $listing));
|
||||
Session\flash_error($message);
|
||||
}
|
||||
|
||||
Response\html(Template\layout('feeds', array(
|
||||
'feeds' => Model\get_feeds(),
|
||||
'nothing_to_read' => Request\int_param('nothing_to_read'),
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'The following feeds are empty, there may be an error : ' =>
|
||||
'Les abonnements suivants sont vides, il doit y avoir une erreur :',
|
||||
'The following feeds are empty, there is maybe an error: %s' =>
|
||||
'Les abonnements suivants sont vides, il y a peut-être une erreur : %s',
|
||||
'Items per page' => 'Nombre d\'éléments par page',
|
||||
'Previous page' => 'Page précédente',
|
||||
'Next page' => 'Page suivante',
|
||||
|
27
model.php
27
model.php
@ -247,28 +247,25 @@ function get_feed($feed_id)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
|
||||
function get_empty_feeds()
|
||||
{
|
||||
$feeds = \PicoTools\singleton('db')
|
||||
->table('feeds')
|
||||
->gt('last_checked', 0)
|
||||
->asc('id')
|
||||
->listing('id', 'title');
|
||||
$ids = array_keys($feeds);
|
||||
->columns('feeds.id', 'feeds.title', 'COUNT(items.id) AS nb_items')
|
||||
->join('items', 'feed_id', 'id')
|
||||
->isNull('feeds.last_checked')
|
||||
->groupBy('items.feed_id')
|
||||
->findAll();
|
||||
|
||||
// fake DISTINCT
|
||||
$not_empty_feeds = \PicoTools\singleton('db')
|
||||
->table('items')
|
||||
->asc('feed_id')
|
||||
->listing('feed_id', 'feed_id');
|
||||
$not_empty_ids = array_keys($not_empty_feeds);
|
||||
foreach ($feeds as $key => &$feed) {
|
||||
|
||||
$diff = array_diff($ids, $not_empty_ids);
|
||||
$return = array();
|
||||
foreach ($diff as $id) {
|
||||
$return[$id] = $feeds[$id];
|
||||
if ($feed['nb_items'] > 0) {
|
||||
unset($feeds[$key]);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
|
||||
|
||||
|
2
vendor/PicoDb/Database.php
vendored
2
vendor/PicoDb/Database.php
vendored
@ -38,7 +38,7 @@ class Database
|
||||
|
||||
public function getLogMessages()
|
||||
{
|
||||
return implode(', ', $this->logs);
|
||||
return $this->logs;
|
||||
}
|
||||
|
||||
|
||||
|
1
vendor/PicoDb/Drivers/Sqlite.php
vendored
1
vendor/PicoDb/Drivers/Sqlite.php
vendored
@ -42,6 +42,7 @@ class Sqlite extends \PDO {
|
||||
|
||||
public function escapeIdentifier($value)
|
||||
{
|
||||
if (strpos($value, '.') !== false) return $value;
|
||||
return '"'.$value.'"';
|
||||
}
|
||||
}
|
73
vendor/PicoDb/Table.php
vendored
73
vendor/PicoDb/Table.php
vendored
@ -14,6 +14,8 @@ class Table
|
||||
private $is_or_condition = false;
|
||||
private $columns = array();
|
||||
private $values = array();
|
||||
private $distinct = false;
|
||||
private $group_by = array();
|
||||
|
||||
private $db;
|
||||
|
||||
@ -134,6 +136,15 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
public function findAllByColumn($column)
|
||||
{
|
||||
$rq = $this->db->execute($this->buildSelectQuery(), $this->values);
|
||||
if (false === $rq) return false;
|
||||
|
||||
return $rq->fetchAll(\PDO::FETCH_COLUMN, 0);
|
||||
}
|
||||
|
||||
|
||||
public function findOne()
|
||||
{
|
||||
$this->limit(1);
|
||||
@ -158,11 +169,13 @@ class Table
|
||||
public function buildSelectQuery()
|
||||
{
|
||||
return sprintf(
|
||||
'SELECT %s FROM %s %s %s %s %s %s',
|
||||
'SELECT %s %s FROM %s %s %s %s %s %s %s',
|
||||
$this->distinct ? 'DISTINCT' : '',
|
||||
empty($this->columns) ? '*' : implode(', ', $this->columns),
|
||||
$this->db->escapeIdentifier($this->table_name),
|
||||
implode(' ', $this->joins),
|
||||
$this->conditions(),
|
||||
empty($this->group_by) ? '' : 'GROUP BY '.implode(', ', $this->group_by),
|
||||
$this->sql_order,
|
||||
$this->sql_limit,
|
||||
$this->sql_offset
|
||||
@ -286,6 +299,13 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
public function groupBy()
|
||||
{
|
||||
$this->group_by = \func_get_args();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function columns()
|
||||
{
|
||||
$this->columns = \func_get_args();
|
||||
@ -293,20 +313,23 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
public function distinct()
|
||||
{
|
||||
$this->columns = \func_get_args();
|
||||
$this->distinct = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function __call($name, array $arguments)
|
||||
{
|
||||
if (2 !== count($arguments)) {
|
||||
|
||||
throw new \LogicException('You must define a column and a value.');
|
||||
}
|
||||
|
||||
$column = $arguments[0];
|
||||
$sql = '';
|
||||
|
||||
switch ($name) {
|
||||
switch (strtolower($name)) {
|
||||
|
||||
case 'in':
|
||||
if (is_array($arguments[1])) {
|
||||
if (isset($arguments[1]) && is_array($arguments[1])) {
|
||||
|
||||
$sql = sprintf(
|
||||
'%s IN (%s)',
|
||||
@ -317,7 +340,7 @@ class Table
|
||||
break;
|
||||
|
||||
case 'notin':
|
||||
if (is_array($arguments[1])) {
|
||||
if (isset($arguments[1]) && is_array($arguments[1])) {
|
||||
|
||||
$sql = sprintf(
|
||||
'%s NOT IN (%s)',
|
||||
@ -338,40 +361,50 @@ class Table
|
||||
break;
|
||||
|
||||
case 'gt':
|
||||
case 'greaterThan':
|
||||
case 'greaterthan':
|
||||
$sql = sprintf('%s > ?', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
|
||||
case 'lt':
|
||||
case 'lowerThan':
|
||||
case 'lowerthan':
|
||||
$sql = sprintf('%s < ?', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
|
||||
case 'gte':
|
||||
case 'greaterThanOrEquals':
|
||||
case 'greaterthanorequals':
|
||||
$sql = sprintf('%s >= ?', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
|
||||
case 'lte':
|
||||
case 'lowerThanOrEquals':
|
||||
case 'lowerthanorequals':
|
||||
$sql = sprintf('%s <= ?', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
|
||||
case 'isnull':
|
||||
$sql = sprintf('%s IS NULL', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
|
||||
case 'notnull':
|
||||
$sql = sprintf('%s IS NOT NULL', $this->db->escapeIdentifier($column));
|
||||
break;
|
||||
}
|
||||
|
||||
if ('' !== $sql) {
|
||||
if ($sql !== '') {
|
||||
|
||||
$this->addCondition($sql);
|
||||
|
||||
if (is_array($arguments[1])) {
|
||||
if (isset($arguments[1])) {
|
||||
|
||||
foreach ($arguments[1] as $value) {
|
||||
if (is_array($arguments[1])) {
|
||||
|
||||
$this->values[] = $value;
|
||||
foreach ($arguments[1] as $value) {
|
||||
$this->values[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else {
|
||||
|
||||
$this->values[] = $arguments[1];
|
||||
$this->values[] = $arguments[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user