Skip to content

Commit

Permalink
DB: Remove unused fields
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Molenaar <[email protected]>
  • Loading branch information
SMillerDev committed Feb 4, 2021
1 parent 5c7838e commit 415370d
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 77 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* [Robin Appelman](mailto:[email protected])
* [Sean Molenaar](mailto:[email protected])
* [Gregor Tätzner](mailto:[email protected])
* [Morris Jobke](mailto:[email protected])
* [Sean Molenaar](mailto:[email protected])
* [Morris Jobke](mailto:[email protected])
* [anoy](mailto:[email protected])
* [Jan-Christoph Borchardt](mailto:[email protected])
* [Daniel Schaal](mailto:[email protected])
Expand Down
24 changes: 0 additions & 24 deletions lib/Db/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class Feed extends Entity implements IAPI, \JsonSerializable
/** @var string|null */
protected $lastModified = '0';
/** @var string|null */
protected $httpEtag = null;
/** @var string|null */
protected $location = null;
/** @var int */
protected $ordering = 0;
Expand Down Expand Up @@ -101,7 +99,6 @@ public function __construct()
$this->addType('articlesPerUpdate', 'integer');
$this->addType('httpLastModified', 'string');
$this->addType('lastModified', 'string');
$this->addType('httpEtag', 'string');
$this->addType('location', 'string');
$this->addType('ordering', 'integer');
$this->addType('fullTextEnabled', 'boolean');
Expand Down Expand Up @@ -177,14 +174,6 @@ public function getFullTextEnabled(): bool
return $this->fullTextEnabled;
}

/**
* @return string|null
*/
public function getHttpEtag(): ?string
{
return $this->httpEtag;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -453,19 +442,6 @@ public function setFullTextEnabled(bool $fullTextEnabled): Feed
return $this;
}

/**
* @param string|null $httpEtag
*/
public function setHttpEtag(?string $httpEtag = null): Feed
{
if ($this->httpEtag !== $httpEtag) {
$this->httpEtag = $httpEtag;
$this->markFieldUpdated('httpEtag');
}

return $this;
}

/**
* @param string|null $httpLastModified
*/
Expand Down
38 changes: 10 additions & 28 deletions lib/Db/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Item extends Entity implements IAPI, \JsonSerializable
protected $author;
/** @var int|null */
protected $pubDate;
/** @var int|null */
protected $updatedDate;
/** @var string|null */
protected $body;
/** @var string|null */
Expand All @@ -53,8 +51,6 @@ class Item extends Entity implements IAPI, \JsonSerializable
protected $mediaDescription;
/** @var int */
protected $feedId;
/** @var int */
protected $status = 0;
/** @var string|null */
protected $lastModified = '0';
/** @var string|null */
Expand All @@ -77,14 +73,12 @@ public function __construct()
$this->addType('title', 'string');
$this->addType('author', 'string');
$this->addType('pubDate', 'integer');
$this->addType('updatedDate', 'integer');
$this->addType('body', 'string');
$this->addType('enclosureMime', 'string');
$this->addType('enclosureLink', 'string');
$this->addType('mediaThumbnail', 'string');
$this->addType('mediaDescription', 'string');
$this->addType('feedId', 'integer');
$this->addType('status', 'integer');
$this->addType('lastModified', 'string');
$this->addType('searchIndex', 'string');
$this->addType('rtl', 'boolean');
Expand Down Expand Up @@ -115,7 +109,6 @@ public static function fromImport($import): Item
$item->setTitle($import['title']);
$item->setAuthor($import['author']);
$item->setPubDate($import['pubDate']);
$item->setUpdatedDate($import['updatedDate']);
$item->setBody($import['body']);
$item->setEnclosureMime($import['enclosureMime']);
$item->setEnclosureLink($import['enclosureLink']);
Expand Down Expand Up @@ -264,14 +257,6 @@ public function getTitle(): ?string
return $this->title;
}

/**
* @return int|null
*/
public function getUpdatedDate(): ?int
{
return $this->updatedDate;
}

/**
* @return null|string
*/
Expand Down Expand Up @@ -303,7 +288,7 @@ public function jsonSerialize(): array
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'updatedDate' => null,
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand Down Expand Up @@ -507,16 +492,6 @@ public function setUnread(bool $unread): self
return $this;
}

public function setUpdatedDate(int $updatedDate = null): self
{
if ($this->updatedDate !== $updatedDate) {
$this->updatedDate = $updatedDate;
$this->markFieldUpdated('updatedDate');
}

return $this;
}

public function setUrl(string $url = null): self
{
$url = trim($url);
Expand All @@ -540,7 +515,7 @@ public function toAPI(): array
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'updatedDate' => null,
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand All @@ -556,6 +531,13 @@ public function toAPI(): array
];
}

/**
* Format for exporting.
*
* @param $feeds
*
* @return array
*/
public function toExport($feeds): array
{
return [
Expand All @@ -564,7 +546,7 @@ public function toExport($feeds): array
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'updatedDate' => null,
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand Down
76 changes: 76 additions & 0 deletions lib/Migration/Version150203Date20210204203051.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace OCA\News\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use function PHPUnit\Framework\returnValue;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version150203Date20210204203051 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('news_items') &&
$schema->getTable('news_items')->hasColumn('last_modified') &&
$schema->getTable('news_items')->getColumn('last_modified')->getUnsigned()
) {
$schema->getTable('news_items')
->getColumn('last_modified')
->setUnsigned(false);
}

if ($schema->hasTable('news_items') &&
$schema->getTable('news_items')->hasColumn('updated_date')
) {
$schema->getTable('news_items')
->dropColumn('updated_date');
}

if ($schema->hasTable('news_items') &&
$schema->getTable('news_items')->hasColumn('status')
) {
$schema->getTable('news_items')
->dropColumn('status');
}

if ($schema->hasTable('news_feeds') &&
$schema->getTable('news_feeds')->hasColumn('http_etag')
) {
$schema->getTable('news_feeds')
->dropColumn('http_etag');
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
1 change: 0 additions & 1 deletion lib/Service/FeedServiceV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ public function fetch(Entity $feed): Entity
}

$feed->setHttpLastModified($fetchedFeed->getHttpLastModified())
->setHttpEtag($fetchedFeed->getHttpEtag())
->setLocation($fetchedFeed->getLocation());

foreach (array_reverse($items) as &$item) {
Expand Down
51 changes: 50 additions & 1 deletion tests/Unit/Db/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ private function createFeed()
$feed = new Feed();
$feed->setId(3);
$feed->setHttpLastModified(44);
$feed->setHttpEtag(45);
$feed->setUrl('http://google.com/some/weird/path');
$feed->setTitle('title');
$feed->setFaviconLink('favicon');
Expand Down Expand Up @@ -129,4 +128,54 @@ public function testSetXSSLink()
}


public function testSetAdded()
{
$feed = new Feed();
$feed->setAdded(15);
$this->assertEquals(15, $feed->getAdded());
}
public function testSetDeletedAt()
{
$feed = new Feed();
$feed->setDeletedAt(15);
$this->assertEquals(15, $feed->getDeletedAt());
}
public function testSetFaviconLink()
{
$feed = new Feed();
$feed->setFaviconLink('https://url');
$this->assertEquals('https://url', $feed->getFaviconLink());
}
public function testSetLastModified()
{
$feed = new Feed();
$feed->setLastModified('15');
$this->assertEquals('15', $feed->getLastModified());
}
public function testSetLastUpdateError()
{
$feed = new Feed();
$feed->setLastUpdateError('NO');
$this->assertEquals('NO', $feed->getLastUpdateError());
}
public function testSetUpdateErrorCount()
{
$feed = new Feed();
$feed->setUpdateErrorCount('5');
$this->assertEquals('5', $feed->getUpdateErrorCount());
}
public function testSetOrdering()
{
$feed = new Feed();
$feed->setOrdering(1);
$this->assertEquals(1, $feed->getOrdering());
}
public function testSetPinned()
{
$feed = new Feed();
$feed->setPinned(true);
$this->assertEquals(true, $feed->getPinned());
}


}
24 changes: 24 additions & 0 deletions tests/Unit/Db/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,28 @@ public function testSerialize()
], $folder->jsonSerialize()
);
}
public function testSetDeletedAt()
{
$folder = new Folder();
$folder->setDeletedAt(15);
$this->assertEquals(15, $folder->getDeletedAt());
}
public function testSetLastModified()
{
$folder = new Folder();
$folder->setLastModified('15');
$this->assertEquals('15', $folder->getLastModified());
}
public function testSetParentId()
{
$folder = new Folder();
$folder->setParentId(15);
$this->assertEquals(15, $folder->getParentId());
}
public function testSetUserId()
{
$folder = new Folder();
$folder->setUserId('15');
$this->assertEquals('15', $folder->getUserId());
}
}
Loading

0 comments on commit 415370d

Please sign in to comment.