Skip to content

Instantly share code, notes, and snippets.

@mnewt
Created May 16, 2017 18:51
Show Gist options
  • Save mnewt/999237d5c2b0cfdd4af1418b84bd9dc6 to your computer and use it in GitHub Desktop.
Save mnewt/999237d5c2b0cfdd4af1418b84bd9dc6 to your computer and use it in GitHub Desktop.

Revisions

  1. mnewt created this gist May 16, 2017.
    34 changes: 34 additions & 0 deletions mark_read.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/bin/env php

    <?php

    require __DIR__.'/miniflux/app/common.php';

    use PicoDb\Database;
    use Miniflux\Model\Item;

    if (php_sapi_name() !== 'cli') {
    die('This script can run only from the command line.'.PHP_EOL);
    }

    if ($argc !== 3) {
    die('Usage: '.$argv[0].' <USER> <STRING>'.PHP_EOL);
    }

    $user_id = (int)$argv[1];
    $string = $argv[2];

    function change_matching_items_status($user_id, $string, $new_status)
    {
    if (! in_array($new_status, array(Item\STATUS_READ, Item\STATUS_UNREAD, Item\STATUS_REMOVED))) {
    return false;
    }

    return Database::getInstance('db')
    ->table(Item\TABLE)
    ->eq('user_id', $user_id)
    ->like('title', '%'.$string.'%')
    ->update(array('status' => $new_status));
    }

    change_matching_items_status($user_id, $string, Item\STATUS_READ);