Plugin Directory

Changeset 2996293


Ignore:
Timestamp:
11/15/2023 10:33:55 AM (2 years ago)
Author:
easycontent
Message:

Trunk update 1.2.0

Location:
easycontent/trunk
Files:
1 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • easycontent/trunk/app/Controllers/Actions/Main/Import.php

    r2825766 r2996293  
    5858        return $this->render( 'admin/pages/import', [
    5959            'table' => $table,
    60             'workflowStages' => $statuses->all(),
    6160            'searchForm' => $searchForm,
    62             'statusesInUse' => $statuses->findInUse(),
     61            'statuses' => $statuses->all(),
    6362        ] );
    6463    }
  • easycontent/trunk/app/Db/Models/Article.php

    r2825766 r2996293  
    1616class Article extends BaseModel
    1717{
    18     public static function getListTableData(SearchArticlesForm $form, $page = 1, $perPage = 20)
    19     {
    20         $wpdb = static::getWpdb();
    21 
    22         $tableName   = static::tableName();
    23         $wsTableName = WorkflowStage::tableName();
    24         $apTableName = ArticlePost::tableName();
    25 
    26         $orderColumn = isset( $_GET['orderby'] )
    27             ? sanitize_text_field( $_GET['orderby'] )
    28             : 'id';
    29 
    30         $order = isset( $_GET['order'] ) && 'asc' === $_GET['order'] ? 'ASC' : 'DESC';
    31 
    32         $offset = ( $page - 1 ) * $perPage;
    33 
    34         $mapping = [
    35             'id' => "`{$tableName}`.`id`",
    36             'topic_name' => '`topic_name`',
    37             'title' => '`title`',
    38             'updated' => '`updated`',
    39             'status' => "`name`",
    40             'last_synced' => '`sync_time`'
    41         ];
    42 
    43         $orderColumn = isset( $mapping[$orderColumn] ) ? $mapping[$orderColumn] : '`id`';
    44 
    45         $whereString = 'WHERE 1=1';
    46 
    47         if ( $searchString = $form->getArticleName() ) {
    48             $whereString .= " AND (`topic_name` LIKE '%{$searchString}%' OR `title` LIKE '%{$searchString}%')";
    49         }
    50 
    51         if ( $workflowStageId = $form->getStatusId() ) {
    52             $whereString .= " AND `current_workflow_stage_id` = {$workflowStageId}";
    53         }
    54 
    55         if ( $form->getSynchronizationStatus() && $form->getSynchronizationStatus() === 'synced' ) {
    56             $whereString .= " AND `sync_time` IS NOT NULL";
    57         } elseif ( $form->getSynchronizationStatus() && $form->getSynchronizationStatus() === 'not_synced' ) {
    58             $whereString .= " AND `sync_time` IS NULL";
    59         }
    60 
    61 
    62         $columns = implode( ', ', array_values( $mapping ) );
    63 
    64         $query = "SELECT {$columns}, `color`, `post_id`
    65             FROM `{$tableName}`
    66             LEFT JOIN `{$wsTableName}` ON `current_workflow_stage_id` = `{$wsTableName}`.`id`
    67             LEFT JOIN `{$apTableName}` ON `{$tableName}`.`id` = `article_id`
    68             {$whereString}
    69             ORDER BY {$orderColumn} {$order}
    70             LIMIT {$perPage} OFFSET {$offset};";
    71 
    72         $result = $wpdb->get_results( $query, ARRAY_A );
    73 
    74         return null === $result ? [] : $result;
    75     }
    76 
    77     public static function countListTableData(SearchArticlesForm $form = null)
    78     {
    79         if ( ! $form ) {
    80             return static::countAll();
    81         }
    82 
    83         $wpdb = static::getWpdb();
    84 
    85         $tableName   = static::tableName();
    86         $wsTableName = WorkflowStage::tableName();
    87         $apTableName = ArticlePost::tableName();
    88 
    89         $whereString = 'WHERE 1=1';
    90 
    91         if ( $searchString = $form->getArticleName() ) {
    92             $whereString .= " AND (`topic_name` LIKE '%{$searchString}%' OR `title` LIKE '%{$searchString}%')";
    93         }
    94 
    95         if ( $workflowStageId = $form->getStatusId() ) {
    96             $whereString .= " AND `current_workflow_stage_id` = {$workflowStageId}";
    97         }
    98 
    99         if ( $form->getSynchronizationStatus() && $form->getSynchronizationStatus() === 'synced' ) {
    100             $whereString .= " AND `sync_time` IS NOT NULL";
    101         } elseif ( $form->getSynchronizationStatus() && $form->getSynchronizationStatus() === 'not_synced' ) {
    102             $whereString .= " AND `sync_time` IS NULL";
    103         }
    104 
    105         $query = "SELECT COUNT(`{$tableName}`.`id`)
    106             FROM `{$tableName}`
    107             LEFT JOIN `{$wsTableName}` ON `current_workflow_stage_id` = `{$wsTableName}`.`id`
    108             LEFT JOIN `{$apTableName}` ON `{$tableName}`.`id` = `article_id`
    109             {$whereString};";
    110 
    111         return (int)$wpdb->get_var( $query );
    112     }
    113 
    11418    public static function getByPostId($postId)
    11519    {
  • easycontent/trunk/app/Implementation/Entity/DbCachedArticlesStorage.php

    r2825766 r2996293  
    4040
    4141    /**
    42      * @return array|CachedArticle[]
    43      */
    44     public function all()
    45     {
    46         global $wpdb;
    47         $query = "SELECT * FROM `{$this->tableName}`;";
    48         $rows = $wpdb->get_results($query, ARRAY_A);
    49 
    50         if (!is_array($rows)) {
    51             return [];
    52         }
    53 
    54         return array_map([$this, 'fromRow'], $rows);
    55     }
    56 
    57     /**
    58      * @param array|CachedArticle[] $items
    59      * @return void
    60      */
    61     public function batchDelete(array $items)
    62     {
    63         $ids = array_map(function(CachedArticle $c) { return $c->getId(); }, $items);
    64         $this->removeByIds($ids);
    65     }
    66 
    67     /**
    6842     * @param CachedArticle $item
    6943     * @return void
    7044     */
    71     public function insert($item)
     45    private function insert($item)
    7246    {
    7347        global $wpdb;
     
    7852    }
    7953
    80     /**
    81      * @param CachedArticle $item
    82      * @return void
    83      */
    8454    public function update($item)
    8555    {
     
    12696    }
    12797
    128     /**
    129      * @inheritDoc
    130      */
     98    /** @inheritDoc */
    13199    public function save(CachedArticle $article, $relatedPost = null)
    132100    {
  • easycontent/trunk/app/Implementation/Entity/DbWorkflowStatusStorage.php

    r2825766 r2996293  
    2727
    2828    /**
    29      * @return array|WorkflowStatus[]
     29     * @return WorkflowStatus[]
    3030     */
    3131    public function all()
     
    4343
    4444    /**
    45      * @param array|WorkflowStatus[] $items
     45     * @param int[] $ids
     46     * @return array<int, WorkflowStatus>
     47     */
     48    public function findByIds(array $ids)
     49    {
     50        if ($ids === []) {
     51            return $this->all();
     52        }
     53
     54        global $wpdb;
     55        $in = implode(', ', array_unique($ids));
     56        $query = "SELECT * FROM `$this->tableName` WHERE `id` IN ($in);";
     57        $rows = $wpdb->get_results($query, ARRAY_A);
     58
     59        if (!is_array($rows)) {
     60            return [];
     61        }
     62
     63        $result = [];
     64
     65        foreach ($rows as $row) {
     66            $result[$row['id']] = $this->fromRow($row);
     67        }
     68
     69        return $result;
     70    }
     71
     72    /**
     73     * @param WorkflowStatus[] $items
    4674     * @return void
    4775     */
     
    151179        return $this->fromRow($row);
    152180    }
    153 
    154     public function findInUse()
    155     {
    156         global $wpdb;
    157         $articlesTableName = "{$wpdb->prefix}easycontent_article";
    158 
    159         $query = "SELECT `{$this->tableName}`.*
    160             FROM `{$this->tableName}`
    161             RIGHT JOIN `{$articlesTableName}` ON `{$articlesTableName}`.`current_workflow_stage_id` = `{$this->tableName}`.`id`
    162             GROUP BY `{$this->tableName}`.`id`;";
    163 
    164         $result = $wpdb->get_results($query, ARRAY_A);
    165 
    166         return null === $result ? [] : array_map([$this, 'fromRow'], $result);
    167     }
    168181}
  • easycontent/trunk/app/Implementation/Entity/DefaultPluginStorage.php

    r2825766 r2996293  
    5656            $this->saveArticleCache($article->getCached());
    5757        } else {
     58            // MS 13.11.2023: Seems that this code will never be reached
    5859            $tableName = "{$wpdb->prefix}easycontent_article";
    5960            $query = "DELETE FROM `{$tableName}` WHERE `id` = %d;";
  • easycontent/trunk/app/Implementation/Entity/RemoteArticlesStorage.php

    r2825766 r2996293  
    2424    public function findByIds(array $ids)
    2525    {
    26         $query = http_build_query(['ids' => $ids]);
    27         $response = $this->httpClient->request(Method::get(), "articles?{$query}");
     26        $response = $this->httpClient->get('articles', ['ids' => $ids]);
    2827        $payload = json_decode($response->get_data(), true);
    2928
     
    6362
    6463        try {
    65             $response = $this->httpClient->request(Method::get(), "articles/{$id->asInt()}");
     64            $response = $this->httpClient->get("articles/{$id->asInt()}");
    6665        } catch (NotFoundException $e) {
    6766            throw RemoteArticleNotFoundException::fromException($e);
     
    119118    {
    120119        $payload = $this->payloadFromArticle($article);
    121         $response = $this->httpClient->request(Method::post(), 'articles', $payload);
     120        $response = $this->httpClient->post('articles', $payload);
    122121        $result = json_decode($response->get_data(), true);
    123122
     
    133132        $uri = "articles/{$article->getId()}/revisions";
    134133        $payload = $this->payloadFromArticle($article);
    135         $this->httpClient->request(Method::post(), $uri, $payload);
     134        $this->httpClient->post($uri, $payload);
    136135    }
    137136
  • easycontent/trunk/app/Implementation/Entity/RemoteEasyContentStorage.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Implementation\Entity;
    44
     5use EasyContent\WordPress\Implementation\Form\SearchArticlesForm;
    56use EasyContent\WordPress\Implementation\Http\Client;
    67use EasyContent\WordPress\Implementation\Http\Method;
    7 use EasyContent\WordPress\Plugin;
    88use EasyContent\WordPress\Source\Api\Entity\Category;
    9 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;
    109use EasyContent\WordPress\Source\Api\Entity\Responses\ConnectionResponse;
    1110use EasyContent\WordPress\Source\Api\Entity\WorkflowStatus;
     
    1413final class RemoteEasyContentStorage implements EasyContentStorage
    1514{
     15    /** @var Client $httpClient */
     16    private $httpClient;
     17    /** @var DbWorkflowStatusStorage $statuses */
     18    private $statuses;
     19
     20    public function __construct(Client $httpClient, DbWorkflowStatusStorage $statuses)
     21    {
     22        $this->httpClient = $httpClient;
     23        $this->statuses = $statuses;
     24    }
     25
    1626    public function fetchAll($key)
    1727    {
    1828        $client = new Client($key);
    19         $response = $client->request(Method::post(), 'connect');
     29        $response = $client->post('connect');
    2030        $payload = json_decode($response->get_data(), true);
    2131        return ConnectionResponse::fromState($payload);
     
    2434    public function getCategories()
    2535    {
    26         $response = $this->getClient()->request(Method::get(), 'categories');
     36        $response = $this->httpClient->get('categories');
    2737        $payload = json_decode($response->get_data(), true);
    2838
     
    3040    }
    3141
    32     public function getArticles()
     42    public function getArticles(SearchArticlesForm $form, $orderColumn, $order, $perPage, $offset)
    3343    {
    34         $response = $this->getClient()->request(Method::get(), 'articles');
    35         $payload = json_decode($response->get_data(), true);
     44        $name = $form->getArticleName();
     45        $statusId = $form->getStatusId();
     46        $syncStatus = $form->getSynchronizationStatus();
    3647
    37         // This code is used to fetch articles from EasyContent.io, convert them to cached articles and update DB cache.
    38         // No need to fetch cached data or related post from DB. However, if this method will be used anywhere else
    39         // we need to be sure everything works fine this way, or we need to add this data to each imported article.
    40         $stub = ['cached' => null, 'related_post' => null,];
     48        $requestParameters = [
     49            'articleName' => $name === '' ? null : $name,
     50            'statusId' => $statusId === 0 ? null : $statusId,
     51            'orderBy' => $orderColumn,
     52            'order' => $order,
     53            'perPage' => $perPage,
     54            'offset' => $offset,
     55            'include' => [],
     56            'exclude' => [],
     57        ];
    4158
    42         return array_map(function(array $row) use ($stub) {
    43             return ImportedArticle::fromState(
    44                 array_merge($row, $stub)
    45             );
    46         }, $payload);
     59        if ($syncStatus === 'synced') {
     60            $requestParameters['include'] = $this->getSyncedArticlesIds();
     61        } elseif ($syncStatus === 'not_synced') {
     62            $requestParameters['exclude'] = $this->getSyncedArticlesIds();
     63        }
     64
     65        $response = $this->httpClient->post('articles?fetch=1', $requestParameters);
     66        $results = json_decode($response->get_data(), true);
     67
     68        if ($results === []) {
     69            return [
     70                'items' => [],
     71                'total' => 0,
     72            ];
     73        }
     74
     75        $stagesIds = array_unique(array_column($results, 'current_workflow_stage_id'));
     76        $stages = $this->statuses->findByIds($stagesIds);
     77        $articlesIds = array_unique(array_column($results, 'id'));
     78        $syncTime = $this->getSyncTime($articlesIds);
     79
     80        foreach ($results as $i => $result) {
     81            if (isset($stages[$result['current_workflow_stage_id']])) {
     82                $results[$i]['color'] = $stages[$result['current_workflow_stage_id']]->getColor();
     83                $results[$i]['name'] = $stages[$result['current_workflow_stage_id']]->getName();
     84            }
     85
     86            if (isset($syncTime[$result['id']])) {
     87                $results[$i]['sync_time'] = $syncTime[$result['id']]['sync_time'];
     88                $results[$i]['post_id'] = $syncTime[$result['id']]['post_id'];
     89            }
     90        }
     91
     92        $headers = $response->get_headers();
     93
     94        return [
     95            'items' => $results,
     96            'total' => $headers['X-Pagination-Total-Count'],
     97        ];
     98    }
     99
     100    /**
     101     * @return int[]
     102     */
     103    private function getSyncedArticlesIds()
     104    {
     105        global $wpdb;
     106        $tableName = "{$wpdb->prefix}easycontent_article_post";
     107        $query = "SELECT `article_id` FROM `$tableName`;";
     108        return $wpdb->get_col($query);
     109    }
     110
     111    /**
     112     * @param int[] $articlesIds
     113     * @return array<int, int>
     114     */
     115    private function getSyncTime(array $articlesIds)
     116    {
     117        if ($articlesIds === []) {
     118            return [];
     119        }
     120
     121        global $wpdb;
     122        $tableName = "{$wpdb->prefix}easycontent_article_post";
     123
     124        $in = implode(', ', array_unique($articlesIds));
     125        $query = "SELECT `article_id`, `post_id`, `sync_time` FROM `$tableName` WHERE `article_id` IN ($in);";
     126        $rows = $wpdb->get_results($query, ARRAY_A);
     127
     128        if (!is_array($rows)) {
     129            return [];
     130        }
     131
     132        $result = [];
     133
     134        foreach ($rows as $row) {
     135            $result[$row['article_id']] = $row;
     136        }
     137
     138        return $result;
    47139    }
    48140
    49141    public function getStatuses()
    50142    {
    51         $response = $this->getClient()->request(Method::get(), 'stages');
     143        $response = $this->httpClient->get('stages');
    52144        $payload = json_decode($response->get_data(), true);
    53145
    54146        return array_map(function(array $row) { return WorkflowStatus::fromState($row); }, $payload);
    55147    }
    56 
    57     private function getClient()
    58     {
    59         return Client::fromPluginSettings();
    60     }
    61148}
  • easycontent/trunk/app/Implementation/Form/BaseForm.php

    r2825766 r2996293  
    1616    final public function __construct(DefaultsProvider $defaults)
    1717    {
    18         if (!$this->fieldsConfig) {
     18        if ($this->fieldsConfig === []) {
    1919            throw new EmptyConfigException;
    2020        }
     
    4747    {
    4848        $this->fieldsValues[$fieldName] = $value;
     49    }
     50
     51    final public function loadFromPost()
     52    {
     53        $this->load($_POST);
     54    }
     55
     56    final public function loadFromGet()
     57    {
     58        $this->load($_GET);
    4959    }
    5060
     
    94104    }
    95105
    96     final public function loadFromPost()
    97     {
    98         $this->load($_POST);
    99     }
    100 
    101     final public function loadFromGet()
    102     {
    103         $this->load($_GET);
    104     }
    105 
    106106    /**
    107107     * @return bool
  • easycontent/trunk/app/Implementation/Http/Client.php

    r2825766 r2996293  
    66use EasyContent\WordPress\Implementation\Http\Exception\NotFoundException;
    77use EasyContent\WordPress\Plugin;
     8use Exception;
     9use WP_HTTP_Requests_Response;
    810
    911final class Client
     
    1113    const BASE_URI = EASYCONTENT_ENDPOINT . '/plugin/api/';
    1214
    13     /** @var string $key */
    14     private $key;
     15    /** @var string $apiKey */
     16    private $apiKey;
    1517    /** @var null|Referer $referer */
    1618    private $referer;
     
    2224    public function __construct($key, $referer = null)
    2325    {
    24         $this->key = $key;
     26        $this->apiKey = $key;
    2527        $this->referer = $referer;
    2628    }
     
    3739
    3840    /**
     41     * @param string $uri
     42     * @param array<string, mixed> $payload
     43     * @return WP_HTTP_Requests_Response
     44     * @throws Exception
     45     */
     46    public function get($uri, array $payload = [])
     47    {
     48        $queryString = $payload === [] ? '' : http_build_query($payload);
     49        $uri = $queryString === '' ? $uri : "$uri?$queryString";
     50        return $this->request(Method::get(), $uri);
     51    }
     52
     53    /**
     54     * @param string $uri
     55     * @param array<string, mixed> $payload
     56     * @return WP_HTTP_Requests_Response
     57     * @throws Exception
     58     */
     59    public function post($uri, array $payload = [])
     60    {
     61        return $this->request(Method::post(), $uri, $payload);
     62    }
     63
     64    /**
    3965     * @param Method $method
    4066     * @param string $uri
    4167     * @param array $payload
    42      * @return \WP_HTTP_Requests_Response
    43      * @throws \Exception
     68     * @return WP_HTTP_Requests_Response
     69     * @throws Exception
    4470     */
    4571    public function request(Method $method, $uri, array $payload = [])
     
    5177
    5278        if (is_wp_error($response)) {
    53             throw new \Exception(implode(PHP_EOL, $response->errors));
     79            throw new Exception(implode(PHP_EOL, $response->errors));
    5480        }
    5581
    56         /** @var null|\WP_HTTP_Requests_Response $responseObject */
     82        /** @var null|WP_HTTP_Requests_Response $responseObject */
    5783        $responseObject = $response['http_response'];
    5884
    5985        if (null === $responseObject) {
    60             throw new \Exception('Unknown error during HTTP request');
     86            throw new Exception('Unknown error during HTTP request');
    6187        }
    6288
     
    6692            throw new NotFoundException;
    6793        } elseif ($statusCode < 200 || $statusCode >= 300) {
    68             throw new \Exception($response['response']['message'], $statusCode);
     94            throw new Exception($response['response']['message'], $statusCode);
    6995        }
    7096
     
    82108
    83109    /**
    84      * @return string[]
     110     * @param string $method
     111     * @param array $payload
     112     * @return array<string, mixed>
     113     */
     114    private function buildArguments($method, array $payload)
     115    {
     116        return [
     117            'method' => $method,
     118            'redirection' => 0,
     119            'headers' => $this->buildHeaders(),
     120            'body' => $payload !== [] ? json_encode($payload) : null,
     121        ];
     122    }
     123
     124    /**
     125     * @return array<string, string>
    85126     */
    86127    private function buildHeaders()
    87128    {
    88129        $headers = [
    89             'Authorization' => "Bearer {$this->key}",
     130            'Authorization' => "Bearer $this->apiKey",
    90131            'Content-Type' => 'application/json',
    91132        ];
    92133
    93         if ($this->referer) {
     134        if ($this->referer !== null) {
    94135            $headers['Referer'] = $this->referer->asString();
    95136        }
     
    97138        return $headers;
    98139    }
    99 
    100     private function buildArguments($method, $body = null)
    101     {
    102         return [
    103             'method' => $method,
    104             'redirection' => 0,
    105             'headers' => $this->buildHeaders(),
    106             'body' => $body ? json_encode($body) : null,
    107         ];
    108     }
    109140}
  • easycontent/trunk/app/Pages/Import/ArticlesListTable.php

    r2825766 r2996293  
    55use EasyContent\WordPress\Db\Models\Article;
    66use EasyContent\WordPress\Helpers\TimeHelper;
     7use EasyContent\WordPress\Implementation\Entity\RemoteEasyContentStorage;
    78use EasyContent\WordPress\Implementation\Form\SearchArticlesForm;
     9use EasyContent\WordPress\Plugin;
    810use EasyContent\WordPress\WP_List_Table;
    911
    1012final class ArticlesListTable extends WP_List_Table
    1113{
     14    /** @var SearchArticlesForm $form */
    1215    private $form;
    1316
    14     public function __construct(SearchArticlesForm $form = null, $args = [])
     17    public function __construct(SearchArticlesForm $form, $args = [])
    1518    {
    1619        parent::__construct($args);
     
    2225        $this->_column_headers = [$this->get_columns(), [], $this->get_sortable_columns()];
    2326
    24         $perPage = $this->get_items_per_page( 'posts_per_page' );
     27        $orderColumn = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : 'id';
     28        $order = isset($_GET['order']) && 'asc' === $_GET['order'] ? 'ASC' : 'DESC';
     29        $page = $this->get_pagenum();
     30        $perPage = $this->get_items_per_page('posts_per_page');
     31        $offset = ($page - 1) * $perPage;
    2532
    26         $this->set_pagination_args( [
    27             'total_items' => Article::countListTableData($this->form),
    28             'per_page'    => $perPage
    29         ] );
     33        /** @var RemoteEasyContentStorage $remote */
     34        $remote = Plugin::getInstance()->getContainer()->get(RemoteEasyContentStorage::class);
    3035
    31         $this->items = $this->form
    32             ? Article::getListTableData($this->form, $this->get_pagenum(), $perPage)
    33             : [];
     36        $result = $remote->getArticles($this->form, $orderColumn, $order, $perPage, $offset);
     37        $this->items = $result['items'];
     38
     39        $this->set_pagination_args([
     40            'total_items' => $result['total'],
     41            'per_page'    => $perPage,
     42        ]);
    3443    }
    3544
     
    5362            'updated' => ['updated', false],
    5463            'status' => ['status', false],
    55             'last_synced' => ['last_synced', false]
    5664        ];
    5765    }
     
    8189    protected function column_status($item)
    8290    {
     91        if (!isset($item['color'])) {
     92            return '<i>No data in local cache</i>';
     93        }
     94
    8395        // TODO: move styles
    8496        return '<span style="border-radius: 50%; background-color: #' . $item['color'] . '; width: 20px; height: 20px; display: inline-block">&nbsp;</span> '
     
    88100    protected function column_last_synced($item)
    89101    {
    90         if ( ! $item['sync_time'] ) {
     102        if ( ! isset($item['sync_time']) ) {
    91103            return __( 'Never', EASYCONTENT_TXTDOMAIN );
    92104        }
  • easycontent/trunk/app/Source/Api/Entity/Responses/ConnectionResponse.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Source\Api\Entity\Responses;
    44
    5 use EasyContent\WordPress\Source\Api\Entity\Article;
    65use EasyContent\WordPress\Source\Api\Entity\Category;
    76use EasyContent\WordPress\Source\Api\Entity\Entity;
     
    1413    /** @var string $projectName */
    1514    private $projectName;
    16     /** @var array|Article[] $articles */
    17     private $articles = [];
    1815    /** @var array|Category[] $categories */
    1916    private $categories = [];
     
    3431            ->setAccountName($data)
    3532            ->setProjectName($data)
    36             ->setArticles($data)
    3733            ->setCategories($data)
    3834            ->setStages($data)
     
    7773        $this->ensureString($data['projectName']);
    7874        $this->projectName = $data['projectName'];
    79         return $this;
    80     }
    81 
    82     /**
    83      * @return array|Article[]
    84      */
    85     public function getArticles()
    86     {
    87         return $this->articles;
    88     }
    89 
    90     /**
    91      * @param array $data
    92      * @return ConnectionResponse
    93      */
    94     private function setArticles(array $data)
    95     {
    96         $this->ensureArrayKeyExists('articles', $data);
    97         $this->ensureArray($data['articles']);
    98 
    99         foreach ($data['articles'] as $articleData) {
    100             $this->articles[] = Article::fromState($articleData);
    101         }
    102 
    10375        return $this;
    10476    }
  • easycontent/trunk/app/Source/Entity/CacheCheckResult.php

    r2825766 r2996293  
    77final class CacheCheckResult
    88{
    9     /** @var array|EntityInterface[] $delete */
     9    /** @var EntityInterface[] $delete */
    1010    private $delete;
    11     /** @var array|EntityInterface[] $insert */
     11    /** @var EntityInterface[] $insert */
    1212    private $insert;
    13     /** @var array|EntityInterface[] $checkUpdate */
     13    /** @var EntityInterface[] $checkUpdate */
    1414    private $checkUpdate;
    15     /** @var array|EntityInterface[] $indexedFreshData */
     15    /** @var EntityInterface[] $indexedFreshData */
    1616    private $indexedFreshData;
    1717
    1818    /**
    19      * @param array|EntityInterface[] $delete
    20      * @param array|EntityInterface[] $insert
    21      * @param array|EntityInterface[] $checkUpdate
     19     * @param EntityInterface[] $delete
     20     * @param EntityInterface[] $insert
     21     * @param EntityInterface[] $checkUpdate
     22     * @param array<int, EntityInterface> $indexedFreshData
    2223     */
    2324    public function __construct(array $delete, array $insert, array $checkUpdate, array $indexedFreshData)
     
    3031
    3132    /**
    32      * @return array|EntityInterface[]
     33     * @return EntityInterface[]
    3334     */
    3435    public function getDelete()
     
    3839
    3940    /**
    40      * @return array|EntityInterface[]
     41     * @return EntityInterface[]
    4142     */
    4243    public function getInsert()
     
    4647
    4748    /**
    48      * @return array|EntityInterface[]
     49     * @return EntityInterface[]
    4950     */
    5051    public function getCheckUpdate()
  • easycontent/trunk/app/Source/Entity/CachedArticle.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Source\Entity;
    44
    5 use EasyContent\WordPress\Source\Api\Entity\Article;
    65use EasyContent\WordPress\Source\Api\Entity\Entity;
    76use EasyContent\WordPress\Source\Api\Entity\EntityInterface;
     
    4039    }
    4140
    42     public static function fromSimple(Article $article)
    43     {
    44         $cached = new self;
    45 
    46         $cached->id = $article->getId();
    47         $cached->currentWorkflowStatusId = $article->getCurrentWorkflowStatusId();
    48         $cached->topicName = $article->getTopicName();
    49         $cached->title = $article->getTitle();
    50         $cached->updated = $article->getUpdated();
    51 
    52         return $cached;
    53     }
    54 
    5541    /**
    5642     * @param array $data
  • easycontent/trunk/app/Source/Entity/CachedArticlesStorage.php

    r2825766 r2996293  
    55use EasyContent\WordPress\Source\Exception\CachedArticleNotFoundException;
    66
    7 interface CachedArticlesStorage extends LocalCache
     7interface CachedArticlesStorage
    88{
    99    /**
     
    2626     */
    2727    public function getById($id);
     28
     29    /**
     30     * @param CachedArticle $item
     31     * @return void
     32     */
     33    public function update($item);
    2834}
  • easycontent/trunk/app/Source/Entity/EasyContentStorage.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Source\Entity;
    44
     5use EasyContent\WordPress\Implementation\Form\SearchArticlesForm;
    56use EasyContent\WordPress\Source\Api\Entity\Category;
    6 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;
    77use EasyContent\WordPress\Source\Api\Entity\Responses\ConnectionResponse;
    88use EasyContent\WordPress\Source\Api\Entity\WorkflowStatus;
     
    2222
    2323    /**
    24      * @return array|ImportedArticle[]
     24     * @param SearchArticlesForm $form
     25     * @param string $orderColumn
     26     * @param string $order ASC or DESC
     27     * @param int $perPage
     28     * @param int $offset
     29     * @return array
    2530     */
    26     public function getArticles();
     31    public function getArticles(SearchArticlesForm $form, $orderColumn, $order, $perPage, $offset);
    2732
    2833    /**
  • easycontent/trunk/app/Source/Entity/WorkflowStatusStorage.php

    r2825766 r2996293  
    2525     */
    2626    public function getById($id);
    27 
    28     /**
    29      * @return array|WorkflowStatus[]
    30      */
    31     public function findInUse();
    3227}
  • easycontent/trunk/app/Source/Services/CacheUpdater.php

    r2825766 r2996293  
    1111    /**
    1212     * @param LocalCache $repository
    13      * @param array|EntityInterface[] $fetchedItems
     13     * @param EntityInterface[] $fetchedItems
    1414     * @return void
    1515     */
     
    3737
    3838    /**
    39      * @param array|EntityInterface[] $old
    40      * @param array|EntityInterface[] $new
     39     * @param EntityInterface[] $old
     40     * @param EntityInterface[] $new
    4141     * @return CacheCheckResult
    4242     */
     
    5555
    5656    /**
    57      * @param array|EntityInterface[] $items
    58      * @return array|EntityInterface[]
     57     * @param EntityInterface[] $items
     58     * @return array<int, EntityInterface>
    5959     */
    6060    private function index(array $items)
  • easycontent/trunk/app/Source/Services/CategoriesMapper.php

    r2825766 r2996293  
    5555
    5656        foreach ($categoriesIds as $termId) {
     57            if (!isset($mappings[$termId])) {
     58                continue;
     59            }
     60
    5761            if ($mappings[$termId] <= 0) {
    5862                continue;
  • easycontent/trunk/app/Source/UseCase/Connect/Handler.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Source\UseCase\Connect;
    44
    5 use EasyContent\WordPress\Source\Api\Entity\Article;
    6 use EasyContent\WordPress\Source\Entity\CachedArticle;
    7 use EasyContent\WordPress\Source\Entity\CachedArticlesStorage;
    85use EasyContent\WordPress\Source\Entity\CategoriesStorage;
    96use EasyContent\WordPress\Source\Entity\EasyContentStorage;
     
    1714    private $pluginStorage;
    1815    private $categories;
    19     private $articles;
    2016    private $statuses;
    2117    private $cacheUpdater;
     
    2521        PluginStorage $pluginStorage,
    2622        CategoriesStorage $categories,
    27         CachedArticlesStorage $articles,
    2823        WorkflowStatusStorage $statuses
    2924    ) {
     
    3126        $this->pluginStorage = $pluginStorage;
    3227        $this->categories = $categories;
    33         $this->articles = $articles;
    3428        $this->statuses = $statuses;
    3529        $this->cacheUpdater = new CacheUpdater;
     
    5549        // Update cache of all tables
    5650        $this->cacheUpdater->updateCache($this->categories, $response->getCategories());
    57         $this->cacheUpdater->updateCache($this->articles, $this->convertArticles($response->getArticles()));
    5851        $this->cacheUpdater->updateCache($this->statuses, $response->getStages());
    5952    }
    60 
    61     /**
    62      * @param array|Article[] $articles
    63      * @return array|CachedArticle[]
    64      */
    65     private function convertArticles(array $articles)
    66     {
    67         return array_map(function(Article $article) { return CachedArticle::fromSimple($article); }, $articles);
    68     }
    6953}
  • easycontent/trunk/app/Source/UseCase/RefreshCachedData/Handler.php

    r2825766 r2996293  
    33namespace EasyContent\WordPress\Source\UseCase\RefreshCachedData;
    44
    5 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;
    6 use EasyContent\WordPress\Source\Entity\CachedArticle;
    7 use EasyContent\WordPress\Source\Entity\CachedArticlesStorage;
    85use EasyContent\WordPress\Source\Entity\CategoriesStorage;
    96use EasyContent\WordPress\Source\Entity\EasyContentStorage;
     
    1512    private $remoteRepository;
    1613    private $categories;
    17     private $articles;
    1814    private $statuses;
    1915    private $cacheUpdater;
     
    2218        EasyContentStorage $remoteRepository,
    2319        CategoriesStorage $categories,
    24         CachedArticlesStorage $articles,
    2520        WorkflowStatusStorage $statuses
    2621    ) {
    2722        $this->remoteRepository = $remoteRepository;
    2823        $this->categories = $categories;
    29         $this->articles = $articles;
    3024        $this->statuses = $statuses;
    3125        $this->cacheUpdater = new CacheUpdater;
     
    3529    {
    3630        $categories = $this->remoteRepository->getCategories();
    37         $articles = $this->remoteRepository->getArticles();
    3831        $statuses = $this->remoteRepository->getStatuses();
    3932
    4033        $this->cacheUpdater->updateCache($this->categories, $categories);
    41         $this->cacheUpdater->updateCache($this->articles, $this->convertArticles($articles));
    4234        $this->cacheUpdater->updateCache($this->statuses, $statuses);
    4335    }
    44 
    45     /**
    46      * @param array|ImportedArticle[] $articles
    47      * @return array|CachedArticle[]
    48      */
    49     private function convertArticles(array $articles)
    50     {
    51         return array_map(function(ImportedArticle $article) { return CachedArticle::fromImported($article); }, $articles);
    52     }
    5336}
  • easycontent/trunk/app/dependencies-config.php

    r2825766 r2996293  
    5050        [Client::class, 'fromPluginSettings'],
    5151    ],
     52    RemoteEasyContentStorage::class => [
     53        [Client::class, 'fromPluginSettings'],
     54        DbWorkflowStatusStorage::class,
     55    ],
    5256    ConnectHandler::class => [
    5357        RemoteEasyContentStorage::class,
    5458        DefaultPluginStorage::class,
    5559        DbCategoriesStorage::class,
    56         DbCachedArticlesStorage::class,
    5760        DbWorkflowStatusStorage::class,
    5861    ],
     
    8689        RemoteEasyContentStorage::class,
    8790        DbCategoriesStorage::class,
    88         DbCachedArticlesStorage::class,
    8991        DbWorkflowStatusStorage::class,
    9092    ],
  • easycontent/trunk/easycontent-wp.php

    r2825775 r2996293  
    44 * Plugin URI:  https://easycontent.io
    55 * Description: Imports articles from EasyContent to your wordpress site and exports articles from your wordpress site to EasyContent
    6  * Version: 1.1.2
     6 * Version: 1.2.0
    77 * Requires at least: 5.0.7
    88 * Requires PHP: 5.6
     
    2121
    2222if ( ! defined( 'EASYCONTENT_PLUGIN_VERSION' ) ) {
    23     define( 'EASYCONTENT_PLUGIN_VERSION', '1.1.2' );
     23    define( 'EASYCONTENT_PLUGIN_VERSION', '1.2.0' );
    2424}
    2525
  • easycontent/trunk/readme.txt

    r2825775 r2996293  
    44Tags:               easycontent, easy content, workflow, approval, collaboration, import, export, manage writers, publishing, content flow, editorial, approval process, content tool
    55Requires at least:  5.0.7
    6 Tested up to:       6.1.1
     6Tested up to:       6.4.1
    77Requires PHP:       5.6
    8 Stable tag:         1.1.2
     8Stable tag:         1.2.0
    99License:            GPL-2.0+
    1010License URI:        http://www.gnu.org/licenses/gpl-2.0.html
     
    6161== Changelog ==
    6262
     63= 1.2.0 =
     64* Reworked "Import from EasyContent" page to be able to interact with huge projects
     65
    6366= 1.1.2 =
    6467* Minor changes
  • easycontent/trunk/vendor/autoload.php

    r2825766 r2996293  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInitdedf6cdf3e9e2575a2973d3cb52d50d1::getLoader();
     7return ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8::getLoader();
  • easycontent/trunk/vendor/composer/autoload_classmap.php

    r2825766 r2996293  
    9595    'EasyContent\\WordPress\\Rest\\RestManager' => $baseDir . '/app/Rest/RestManager.php',
    9696    'EasyContent\\WordPress\\Singleton' => $baseDir . '/app/Singleton.php',
    97     'EasyContent\\WordPress\\Source\\Api\\Entity\\Article' => $baseDir . '/app/Source/Api/Entity/Article.php',
    9897    'EasyContent\\WordPress\\Source\\Api\\Entity\\BaseArticle' => $baseDir . '/app/Source/Api/Entity/BaseArticle.php',
    9998    'EasyContent\\WordPress\\Source\\Api\\Entity\\Category' => $baseDir . '/app/Source/Api/Entity/Category.php',
  • easycontent/trunk/vendor/composer/autoload_real.php

    r2825766 r2996293  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitdedf6cdf3e9e2575a2973d3cb52d50d1
     5class ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInitdedf6cdf3e9e2575a2973d3cb52d50d1', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    29         spl_autoload_unregister(array('ComposerAutoloaderInitdedf6cdf3e9e2575a2973d3cb52d50d1', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8', 'loadClassLoader'));
    3030
    3131        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3333            require __DIR__ . '/autoload_static.php';
    3434
    35             call_user_func(\Composer\Autoload\ComposerStaticInitdedf6cdf3e9e2575a2973d3cb52d50d1::getInitializer($loader));
     35            call_user_func(\Composer\Autoload\ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::getInitializer($loader));
    3636        } else {
    3737            $map = require __DIR__ . '/autoload_namespaces.php';
  • easycontent/trunk/vendor/composer/autoload_static.php

    r2825766 r2996293  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitdedf6cdf3e9e2575a2973d3cb52d50d1
     7class ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    118118        'EasyContent\\WordPress\\Rest\\RestManager' => __DIR__ . '/../..' . '/app/Rest/RestManager.php',
    119119        'EasyContent\\WordPress\\Singleton' => __DIR__ . '/../..' . '/app/Singleton.php',
    120         'EasyContent\\WordPress\\Source\\Api\\Entity\\Article' => __DIR__ . '/../..' . '/app/Source/Api/Entity/Article.php',
    121120        'EasyContent\\WordPress\\Source\\Api\\Entity\\BaseArticle' => __DIR__ . '/../..' . '/app/Source/Api/Entity/BaseArticle.php',
    122121        'EasyContent\\WordPress\\Source\\Api\\Entity\\Category' => __DIR__ . '/../..' . '/app/Source/Api/Entity/Category.php',
     
    195194    {
    196195        return \Closure::bind(function () use ($loader) {
    197             $loader->prefixLengthsPsr4 = ComposerStaticInitdedf6cdf3e9e2575a2973d3cb52d50d1::$prefixLengthsPsr4;
    198             $loader->prefixDirsPsr4 = ComposerStaticInitdedf6cdf3e9e2575a2973d3cb52d50d1::$prefixDirsPsr4;
    199             $loader->classMap = ComposerStaticInitdedf6cdf3e9e2575a2973d3cb52d50d1::$classMap;
     196            $loader->prefixLengthsPsr4 = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$prefixLengthsPsr4;
     197            $loader->prefixDirsPsr4 = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$prefixDirsPsr4;
     198            $loader->classMap = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$classMap;
    200199
    201200        }, null, ClassLoader::class);
  • easycontent/trunk/views/admin/pages/import.php

    r2825766 r2996293  
    33 * @var View $this
    44 * @var EasyContent\WordPress\Pages\Import\ArticlesListTable $table
    5  * @var array|EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $workflowStages
    6  * @var array|EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statusesInUse
     5 * @var EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statuses
    76 * @var SearchArticlesForm $searchForm
    87 */
     
    2726
    2827        echo (new View)->render('admin/pages/import/table-filters', [
    29             'statusesInUse' => $statusesInUse,
     28            'statuses' => $statuses,
    3029            'searchForm' => $searchForm,
    3130        ]);
     
    4039            </button>
    4140
    42             <?php if ( $workflowStages ) : ?>
     41            <?php if ( $statuses !== [] ) : ?>
    4342                <?= esc_html__( 'On import, change EasyContent status to', EASYCONTENT_TXTDOMAIN ) ?>
    4443
     
    4645                    <option value=""><?= esc_html__( "Don't change status", EASYCONTENT_TXTDOMAIN ) ?></option>
    4746
    48                     <?php foreach ( $workflowStages as $stage ) : ?>
     47                    <?php foreach ( $statuses as $stage ) : ?>
    4948                        <option value="<?= esc_attr( $stage->getId() ) ?>">
    5049                            <?= esc_html( $stage->getName() ) ?>
     
    6261            </button>
    6362
    64             <?php if ( $workflowStages ) : ?>
     63            <?php if ( $statuses !== [] ) : ?>
    6564                <?= esc_html__( 'On import, change EasyContent status to', EASYCONTENT_TXTDOMAIN ) ?>
    6665
     
    6867                    <option value=""><?= esc_html__( "Don't change status", EASYCONTENT_TXTDOMAIN ) ?></option>
    6968
    70                     <?php foreach ( $workflowStages as $stage ) : ?>
     69                    <?php foreach ( $statuses as $stage ) : ?>
    7170                        <option value="<?= esc_attr( $stage->getId() ) ?>">
    7271                            <?= esc_html( $stage->getName() ) ?>
  • easycontent/trunk/views/admin/pages/import/table-filters.php

    r2825766 r2996293  
    22/**
    33 * @var EasyContent\WordPress\View $this
    4  * @var array|EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statusesInUse
     4 * @var EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statuses
    55 * @var EasyContent\WordPress\Implementation\Form\SearchArticlesForm $searchForm
    66 */
     
    1919            value="<?= esc_attr($searchForm->getArticleName()) ?>">
    2020
    21         <?php if ($statusesInUse) : ?>
     21        <?php if ($statuses !== []) : ?>
    2222            <label for="ec-workflow-stage" class="screen-reader-text"><?= esc_html__( 'Status', EASYCONTENT_TXTDOMAIN ) ?></label>
    2323            <select name="<?= esc_attr(sprintf('%s[%s]', $searchForm::NAME, $searchForm::FIELD_WORKFLOW_STATUS_ID)) ?>" id="ec-workflow-stage">
     
    2626                </option>
    2727
    28                 <?php foreach ($statusesInUse as $status) : ?>
     28                <?php foreach ($statuses as $status) : ?>
    2929                    <option value="<?= esc_attr($status->getId()) ?>" <?php selected($searchForm->getStatusId(), $status->getId()) ?>>
    3030                        <?= esc_html($status->getName()) ?>
Note: See TracChangeset for help on using the changeset viewer.