|
|
|
<?php
|
|
|
|
|
|
|
|
class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
|
|
|
|
|
|
|
|
const DEFAULTCATEGORYID = 1;
|
|
|
|
|
|
|
|
public function resetDefaultCategoryName() {
|
|
|
|
//FreshRSS 1.15.1
|
|
|
|
$stm = $this->pdo->prepare('UPDATE `_category` SET name = :name WHERE id = :id');
|
|
|
|
if ($stm) {
|
|
|
|
$stm->bindValue(':id', self::DEFAULTCATEGORYID, PDO::PARAM_INT);
|
|
|
|
$stm->bindValue(':name', 'Uncategorized');
|
|
|
|
}
|
|
|
|
return $stm && $stm->execute();
|
|
|
|
}
|
|
|
|
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
protected function addColumn($name) {
|
|
|
|
Minz_Log::warning(__method__ . ': ' . $name);
|
|
|
|
try {
|
|
|
|
if ('attributes' === $name) { //v1.15.0
|
|
|
|
$ok = $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN attributes TEXT') !== false;
|
|
|
|
|
|
|
|
$stm = $this->pdo->query('SELECT * FROM `_feed`');
|
|
|
|
$feeds = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$stm = $this->pdo->prepare('UPDATE `_feed` SET attributes = :attributes WHERE id = :id');
|
|
|
|
foreach ($feeds as $feed) {
|
|
|
|
if (empty($feed['keep_history']) || empty($feed['id'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$keepHistory = $feed['keep_history'];
|
|
|
|
$attributes = empty($feed['attributes']) ? [] : json_decode($feed['attributes'], true);
|
|
|
|
if (is_string($attributes)) { //Legacy risk of double-encoding
|
|
|
|
$attributes = json_decode($attributes, true);
|
|
|
|
}
|
|
|
|
if (!is_array($attributes)) {
|
|
|
|
$attributes = [];
|
|
|
|
}
|
|
|
|
if ($keepHistory > 0) {
|
|
|
|
$attributes['archiving']['keep_min'] = intval($keepHistory);
|
|
|
|
} elseif ($keepHistory == -1) { //Infinite
|
|
|
|
$attributes['archiving']['keep_period'] = false;
|
|
|
|
$attributes['archiving']['keep_max'] = false;
|
|
|
|
$attributes['archiving']['keep_min'] = false;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$stm->bindValue(':id', $feed['id'], PDO::PARAM_INT);
|
|
|
|
$stm->bindValue(':attributes', json_encode($attributes, JSON_UNESCAPED_SLASHES));
|
|
|
|
$stm->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->pdo->dbType() !== 'sqlite') { //SQLite does not support DROP COLUMN
|
|
|
|
$this->pdo->exec('ALTER TABLE `_feed` DROP COLUMN keep_history');
|
|
|
|
} else {
|
|
|
|
$this->pdo->exec('DROP INDEX IF EXISTS feed_keep_history_index'); //SQLite at least drop index
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->resetDefaultCategoryName();
|
|
|
|
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
return $ok;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
Minz_Log::error(__method__ . ': ' . $e->getMessage());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function autoUpdateDb($errorInfo) {
|
|
|
|
if (isset($errorInfo[0])) {
|
|
|
|
if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
|
|
|
|
foreach (['attributes'] as $column) {
|
|
|
|
if (stripos($errorInfo[2], $column) !== false) {
|
|
|
|
return $this->addColumn($column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addCategory($valuesTmp) {
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$sql = 'INSERT INTO `_category`(name, attributes) '
|
|
|
|
. 'SELECT * FROM (SELECT TRIM(?) AS name, TRIM(?) AS attributes) c2 ' //TRIM() to provide a type hint as text
|
|
|
|
. 'WHERE NOT EXISTS (SELECT 1 FROM `_tag` WHERE name = TRIM(?))'; //No tag of the same name
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
|
|
|
|
$valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
if (!isset($valuesTmp['attributes'])) {
|
|
|
|
$valuesTmp['attributes'] = [];
|
|
|
|
}
|
|
|
|
$values = array(
|
|
|
|
$valuesTmp['name'],
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES),
|
|
|
|
$valuesTmp['name'],
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($stm && $stm->execute($values)) {
|
|
|
|
return $this->pdo->lastInsertId('`_category_id_seq`');
|
|
|
|
} else {
|
|
|
|
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
if ($this->autoUpdateDb($info)) {
|
|
|
|
return $this->addCategory($valuesTmp);
|
|
|
|
}
|
|
|
|
Minz_Log::error('SQL error addCategory: ' . json_encode($info));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addCategoryObject($category) {
|
|
|
|
$cat = $this->searchByName($category->name());
|
|
|
|
if (!$cat) {
|
|
|
|
// Category does not exist yet in DB so we add it before continue
|
|
|
|
$values = array(
|
|
|
|
'name' => $category->name(),
|
|
|
|
);
|
|
|
|
return $this->addCategory($values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cat->id();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateCategory($id, $valuesTmp) {
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$sql = 'UPDATE `_category` SET name=?, attributes=? WHERE id=? '
|
|
|
|
. 'AND NOT EXISTS (SELECT 1 FROM `_tag` WHERE name = ?)'; //No tag of the same name
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
|
|
|
|
$valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
if (!isset($valuesTmp['attributes'])) {
|
|
|
|
$valuesTmp['attributes'] = [];
|
|
|
|
}
|
|
|
|
$values = array(
|
|
|
|
$valuesTmp['name'],
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES),
|
|
|
|
$id,
|
|
|
|
$valuesTmp['name'],
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($stm && $stm->execute($values)) {
|
|
|
|
return $stm->rowCount();
|
|
|
|
} else {
|
|
|
|
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
if ($this->autoUpdateDb($info)) {
|
|
|
|
return $this->updateCategory($valuesTmp);
|
|
|
|
}
|
|
|
|
Minz_Log::error('SQL error updateCategory: ' . json_encode($info));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteCategory($id) {
|
|
|
|
if ($id <= self::DEFAULTCATEGORYID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$sql = 'DELETE FROM `_category` WHERE id=:id';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
$stm->bindParam(':id', $id, PDO::PARAM_INT);
|
|
|
|
if ($stm && $stm->execute()) {
|
|
|
|
return $stm->rowCount();
|
|
|
|
} else {
|
|
|
|
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
Minz_Log::error('SQL error deleteCategory: ' . json_encode($info));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function selectAll() {
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$sql = 'SELECT id, name, attributes FROM `_category`';
|
|
|
|
$stm = $this->pdo->query($sql);
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
if ($stm != false) {
|
|
|
|
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
|
|
|
|
yield $row;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$info = $this->pdo->errorInfo();
|
|
|
|
if ($this->autoUpdateDb($info)) {
|
|
|
|
foreach ($this->selectAll() as $category) { // `yield from` requires PHP 7+
|
|
|
|
yield $category;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Minz_Log::error(__method__ . ' error: ' . json_encode($info));
|
|
|
|
yield false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function searchById($id) {
|
|
|
|
$sql = 'SELECT * FROM `_category` WHERE id=:id';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
$stm->bindParam(':id', $id, PDO::PARAM_INT);
|
|
|
|
$stm->execute();
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$cat = self::daoToCategory($res);
|
|
|
|
|
|
|
|
if (isset($cat[0])) {
|
|
|
|
return $cat[0];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function searchByName($name) {
|
|
|
|
$sql = 'SELECT * FROM `_category` WHERE name=:name';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
if ($stm == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$stm->bindParam(':name', $name);
|
|
|
|
$stm->execute();
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$cat = self::daoToCategory($res);
|
|
|
|
if (isset($cat[0])) {
|
|
|
|
return $cat[0];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listSortedCategories($prePopulateFeeds = true, $details = false) {
|
|
|
|
$categories = $this->listCategories($prePopulateFeeds, $details);
|
|
|
|
|
|
|
|
if (!is_array($categories)) {
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
uasort($categories, function ($a, $b) {
|
|
|
|
$aPosition = $a->attributes('position');
|
|
|
|
$bPosition = $b->attributes('position');
|
|
|
|
if ($aPosition === $bPosition) {
|
|
|
|
return ($a->name() < $b->name()) ? -1 : 1;
|
|
|
|
} elseif (null === $aPosition) {
|
|
|
|
return 1;
|
|
|
|
} elseif (null === $bPosition) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return ($aPosition < $bPosition) ? -1 : 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listCategories($prePopulateFeeds = true, $details = false) {
|
|
|
|
if ($prePopulateFeeds) {
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$sql = 'SELECT c.id AS c_id, c.name AS c_name, c.attributes AS c_attributes, '
|
|
|
|
. ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.`cache_nbEntries`, f.`cache_nbUnreads`, f.ttl ')
|
|
|
|
. 'FROM `_category` c '
|
|
|
|
. 'LEFT OUTER JOIN `_feed` f ON f.category=c.id '
|
|
|
|
. 'WHERE f.priority >= :priority_normal '
|
|
|
|
. 'GROUP BY f.id, c_id '
|
|
|
|
. 'ORDER BY c.name, f.name';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$values = [ ':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL ];
|
|
|
|
if ($stm && $stm->execute($values)) {
|
|
|
|
return self::daoToCategoryPrepopulated($stm->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
} else {
|
|
|
|
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
|
|
|
|
if ($this->autoUpdateDb($info)) {
|
|
|
|
return $this->listCategories($prePopulateFeeds, $details);
|
|
|
|
}
|
|
|
|
Minz_Log::error('SQL error listCategories: ' . json_encode($info));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$sql = 'SELECT * FROM `_category` ORDER BY name';
|
|
|
|
$stm = $this->pdo->query($sql);
|
|
|
|
return self::daoToCategory($stm->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefault() {
|
|
|
|
$sql = 'SELECT * FROM `_category` WHERE id=:id';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
$stm->bindValue(':id', self::DEFAULTCATEGORYID, PDO::PARAM_INT);
|
|
|
|
$stm->execute();
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$cat = self::daoToCategory($res);
|
|
|
|
|
|
|
|
if (isset($cat[0])) {
|
|
|
|
return $cat[0];
|
|
|
|
} else {
|
|
|
|
if (FreshRSS_Context::$isCli) {
|
|
|
|
fwrite(STDERR, 'FreshRSS database error: Default category not found!' . "\n");
|
|
|
|
}
|
|
|
|
Minz_Log::error('FreshRSS database error: Default category not found!');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function checkDefault() {
|
|
|
|
$def_cat = $this->searchById(self::DEFAULTCATEGORYID);
|
|
|
|
|
|
|
|
if ($def_cat == null) {
|
|
|
|
$cat = new FreshRSS_Category(_t('gen.short.default_category'));
|
|
|
|
$cat->_id(self::DEFAULTCATEGORYID);
|
|
|
|
|
|
|
|
$sql = 'INSERT INTO `_category`(id, name) VALUES(?, ?)';
|
|
|
|
if ($this->pdo->dbType() === 'pgsql') {
|
|
|
|
//Force call to nextval()
|
|
|
|
$sql .= " RETURNING nextval('`_category_id_seq`');";
|
|
|
|
}
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
|
|
|
|
$values = array(
|
|
|
|
$cat->id(),
|
|
|
|
$cat->name(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($stm && $stm->execute($values)) {
|
|
|
|
return $this->pdo->lastInsertId('`_category_id_seq`');
|
|
|
|
} else {
|
|
|
|
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
|
|
|
|
Minz_Log::error('SQL error check default category: ' . json_encode($info));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count() {
|
|
|
|
$sql = 'SELECT COUNT(*) AS count FROM `_category`';
|
|
|
|
$stm = $this->pdo->query($sql);
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return $res[0]['count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function countFeed($id) {
|
|
|
|
$sql = 'SELECT COUNT(*) AS count FROM `_feed` WHERE category=:id';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
$stm->bindParam(':id', $id, PDO::PARAM_INT);
|
|
|
|
$stm->execute();
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return $res[0]['count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function countNotRead($id) {
|
|
|
|
$sql = 'SELECT COUNT(*) AS count FROM `_entry` e INNER JOIN `_feed` f ON e.id_feed=f.id WHERE category=:id AND e.is_read=0';
|
|
|
|
$stm = $this->pdo->prepare($sql);
|
|
|
|
$stm->bindParam(':id', $id, PDO::PARAM_INT);
|
|
|
|
$stm->execute();
|
|
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return $res[0]['count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function findFeed($categories, $feed_id) {
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
foreach ($category->feeds() as $feed) {
|
|
|
|
if ($feed->id() === $feed_id) {
|
|
|
|
return $feed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function CountUnreads($categories, $minPriority = 0) {
|
|
|
|
$n = 0;
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
foreach ($category->feeds() as $feed) {
|
|
|
|
if ($feed->priority() >= $minPriority) {
|
|
|
|
$n += $feed->nbNotRead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $n;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function daoToCategoryPrepopulated($listDAO) {
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
if (!is_array($listDAO)) {
|
|
|
|
$listDAO = array($listDAO);
|
|
|
|
}
|
|
|
|
|
|
|
|
$previousLine = null;
|
|
|
|
$feedsDao = array();
|
|
|
|
$feedDao = FreshRSS_Factory::createFeedDAO();
|
|
|
|
foreach ($listDAO as $line) {
|
|
|
|
if (!empty($previousLine['c_id']) && $line['c_id'] !== $previousLine['c_id']) {
|
|
|
|
// End of the current category, we add it to the $list
|
|
|
|
$cat = new FreshRSS_Category(
|
|
|
|
$previousLine['c_name'],
|
|
|
|
$feedDao->daoToFeed($feedsDao, $previousLine['c_id'])
|
|
|
|
);
|
|
|
|
$cat->_id($previousLine['c_id']);
|
|
|
|
$cat->_attributes('', $previousLine['c_attributes']);
|
|
|
|
$list[$previousLine['c_id']] = $cat;
|
|
|
|
|
|
|
|
$feedsDao = array(); //Prepare for next category
|
|
|
|
}
|
|
|
|
|
|
|
|
$previousLine = $line;
|
|
|
|
$feedsDao[] = $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the last category
|
|
|
|
if ($previousLine != null) {
|
|
|
|
$cat = new FreshRSS_Category(
|
|
|
|
$previousLine['c_name'],
|
|
|
|
$feedDao->daoToFeed($feedsDao, $previousLine['c_id'])
|
|
|
|
);
|
|
|
|
$cat->_id($previousLine['c_id']);
|
|
|
|
$cat->_attributes('', $previousLine['c_attributes']);
|
|
|
|
$list[$previousLine['c_id']] = $cat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function daoToCategory($listDAO) {
|
|
|
|
$list = array();
|
|
|
|
|
|
|
|
if (!is_array($listDAO)) {
|
|
|
|
$listDAO = array($listDAO);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($listDAO as $key => $dao) {
|
|
|
|
$cat = new FreshRSS_Category(
|
|
|
|
$dao['name']
|
|
|
|
);
|
|
|
|
$cat->_id($dao['id']);
|
Feature/new archiving (#2335)
* Change archiving config page layout
I've changed some wording and moved actions into a
maintenance section.
* Update purge action
Now we have more control on the purge action. The configuration allows
us to choose what to keep and what to discard in a more precise way.
At the moment, the configuration applies for all feeds.
* Add purge configuration on feed level
Now the extend purge configuration is available on feed level.
It is stored as attributes and will be used in the purge action.
* Update purge action
Now the purge action uses the feed configuration if it exists and
defaults on user configuration if not.
* Add empty option in period list
* Fix configuration warnings
* Add archiving configuration on categories
See #2369
* Add user info back
* Add explanations in UI
* Fixes for SQLite + error + misc.
* Fix invalid feed reference
* Short array syntax
Only for new code, so far
* Fix prefix error
* Query performance, default values
Work in progress
* Fix default values and confirm before leaving
Form cancel and confirm changes before leaving were broken.
And start taking advantage of the short echo syntax `<?= ?>` as we have
moved to PHP 5.4+
* More work
* Tuning SQL
* Fix MariaDB + performance issue
* SQL performance
* Fix SQLite bug
* Fix some attributes JSON encoding bugs
Especially for SQLite export/import
* More uniform, fix bugs
More uniform between global, category, feed settings
* Drop special cases for old articles during refresh
Instead will use lastSeen date with the new archiving logic.
This was generating problems anyway
https://github.com/FreshRSS/FreshRSS/issues/2154
* Draft drop index keep_history
Not needed anymore
* MySQL typo
Now properly tested with MySQL, PostgreSQL, SQLite
* More work for legacy values
Important to avoid overriding user's preference and risking deleting
data erroneously
* Fix PHP 7.3 / 7.4 warnings
@aledeg "Trying to use values of type null, bool, int, float or resource
as an array (such as $null["key"]) will now generate a notice. "
https://php.net/migration74.incompatible
* Reintroduce min articles and take care of legacy parameters
* A few changes forgotten
* Draft of migration + DROP of feed.keep_history
* Fix several errors
And give up using const for SQL to allow multiple database types (and we
cannot redefine a const)
* Add keep_min to categories + factorise archiving logic
* Legacy fix
* Fix bug yield from
* Minor: Use JSON_UNESCAPED_SLASHE for attributes
And make more uniform
* Fix sign and missing variable
* Fine tune the logic
5 years ago
|
|
|
$cat->_attributes('', isset($dao['attributes']) ? $dao['attributes'] : '');
|
|
|
|
$cat->_isDefault(static::DEFAULTCATEGORYID === intval($dao['id']));
|
|
|
|
$list[$key] = $cat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
}
|