Changeset 2996293
- Timestamp:
- 11/15/2023 10:33:55 AM (2 years ago)
- Location:
- easycontent/trunk
- Files:
-
- 1 deleted
- 29 edited
-
app/Controllers/Actions/Main/Import.php (modified) (1 diff)
-
app/Db/Models/Article.php (modified) (1 diff)
-
app/Implementation/Entity/DbCachedArticlesStorage.php (modified) (3 diffs)
-
app/Implementation/Entity/DbWorkflowStatusStorage.php (modified) (3 diffs)
-
app/Implementation/Entity/DefaultPluginStorage.php (modified) (1 diff)
-
app/Implementation/Entity/RemoteArticlesStorage.php (modified) (4 diffs)
-
app/Implementation/Entity/RemoteEasyContentStorage.php (modified) (4 diffs)
-
app/Implementation/Form/BaseForm.php (modified) (3 diffs)
-
app/Implementation/Http/Client.php (modified) (8 diffs)
-
app/Pages/Import/ArticlesListTable.php (modified) (5 diffs)
-
app/Source/Api/Entity/Article.php (deleted)
-
app/Source/Api/Entity/Responses/ConnectionResponse.php (modified) (4 diffs)
-
app/Source/Entity/CacheCheckResult.php (modified) (4 diffs)
-
app/Source/Entity/CachedArticle.php (modified) (2 diffs)
-
app/Source/Entity/CachedArticlesStorage.php (modified) (2 diffs)
-
app/Source/Entity/EasyContentStorage.php (modified) (2 diffs)
-
app/Source/Entity/WorkflowStatusStorage.php (modified) (1 diff)
-
app/Source/Services/CacheUpdater.php (modified) (3 diffs)
-
app/Source/Services/CategoriesMapper.php (modified) (1 diff)
-
app/Source/UseCase/Connect/Handler.php (modified) (5 diffs)
-
app/Source/UseCase/RefreshCachedData/Handler.php (modified) (4 diffs)
-
app/dependencies-config.php (modified) (2 diffs)
-
easycontent-wp.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
vendor/autoload.php (modified) (1 diff)
-
vendor/composer/autoload_classmap.php (modified) (1 diff)
-
vendor/composer/autoload_real.php (modified) (3 diffs)
-
vendor/composer/autoload_static.php (modified) (3 diffs)
-
views/admin/pages/import.php (modified) (6 diffs)
-
views/admin/pages/import/table-filters.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easycontent/trunk/app/Controllers/Actions/Main/Import.php
r2825766 r2996293 58 58 return $this->render( 'admin/pages/import', [ 59 59 'table' => $table, 60 'workflowStages' => $statuses->all(),61 60 'searchForm' => $searchForm, 62 'statuses InUse' => $statuses->findInUse(),61 'statuses' => $statuses->all(), 63 62 ] ); 64 63 } -
easycontent/trunk/app/Db/Models/Article.php
r2825766 r2996293 16 16 class Article extends BaseModel 17 17 { 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 114 18 public static function getByPostId($postId) 115 19 { -
easycontent/trunk/app/Implementation/Entity/DbCachedArticlesStorage.php
r2825766 r2996293 40 40 41 41 /** 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[] $items59 * @return void60 */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 /**68 42 * @param CachedArticle $item 69 43 * @return void 70 44 */ 71 p ublicfunction insert($item)45 private function insert($item) 72 46 { 73 47 global $wpdb; … … 78 52 } 79 53 80 /**81 * @param CachedArticle $item82 * @return void83 */84 54 public function update($item) 85 55 { … … 126 96 } 127 97 128 /** 129 * @inheritDoc 130 */ 98 /** @inheritDoc */ 131 99 public function save(CachedArticle $article, $relatedPost = null) 132 100 { -
easycontent/trunk/app/Implementation/Entity/DbWorkflowStatusStorage.php
r2825766 r2996293 27 27 28 28 /** 29 * @return array|WorkflowStatus[]29 * @return WorkflowStatus[] 30 30 */ 31 31 public function all() … … 43 43 44 44 /** 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 46 74 * @return void 47 75 */ … … 151 179 return $this->fromRow($row); 152 180 } 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 }168 181 } -
easycontent/trunk/app/Implementation/Entity/DefaultPluginStorage.php
r2825766 r2996293 56 56 $this->saveArticleCache($article->getCached()); 57 57 } else { 58 // MS 13.11.2023: Seems that this code will never be reached 58 59 $tableName = "{$wpdb->prefix}easycontent_article"; 59 60 $query = "DELETE FROM `{$tableName}` WHERE `id` = %d;"; -
easycontent/trunk/app/Implementation/Entity/RemoteArticlesStorage.php
r2825766 r2996293 24 24 public function findByIds(array $ids) 25 25 { 26 $query = http_build_query(['ids' => $ids]); 27 $response = $this->httpClient->request(Method::get(), "articles?{$query}"); 26 $response = $this->httpClient->get('articles', ['ids' => $ids]); 28 27 $payload = json_decode($response->get_data(), true); 29 28 … … 63 62 64 63 try { 65 $response = $this->httpClient-> request(Method::get(),"articles/{$id->asInt()}");64 $response = $this->httpClient->get("articles/{$id->asInt()}"); 66 65 } catch (NotFoundException $e) { 67 66 throw RemoteArticleNotFoundException::fromException($e); … … 119 118 { 120 119 $payload = $this->payloadFromArticle($article); 121 $response = $this->httpClient-> request(Method::post(),'articles', $payload);120 $response = $this->httpClient->post('articles', $payload); 122 121 $result = json_decode($response->get_data(), true); 123 122 … … 133 132 $uri = "articles/{$article->getId()}/revisions"; 134 133 $payload = $this->payloadFromArticle($article); 135 $this->httpClient-> request(Method::post(),$uri, $payload);134 $this->httpClient->post($uri, $payload); 136 135 } 137 136 -
easycontent/trunk/app/Implementation/Entity/RemoteEasyContentStorage.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Implementation\Entity; 4 4 5 use EasyContent\WordPress\Implementation\Form\SearchArticlesForm; 5 6 use EasyContent\WordPress\Implementation\Http\Client; 6 7 use EasyContent\WordPress\Implementation\Http\Method; 7 use EasyContent\WordPress\Plugin;8 8 use EasyContent\WordPress\Source\Api\Entity\Category; 9 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;10 9 use EasyContent\WordPress\Source\Api\Entity\Responses\ConnectionResponse; 11 10 use EasyContent\WordPress\Source\Api\Entity\WorkflowStatus; … … 14 13 final class RemoteEasyContentStorage implements EasyContentStorage 15 14 { 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 16 26 public function fetchAll($key) 17 27 { 18 28 $client = new Client($key); 19 $response = $client-> request(Method::post(),'connect');29 $response = $client->post('connect'); 20 30 $payload = json_decode($response->get_data(), true); 21 31 return ConnectionResponse::fromState($payload); … … 24 34 public function getCategories() 25 35 { 26 $response = $this-> getClient()->request(Method::get(),'categories');36 $response = $this->httpClient->get('categories'); 27 37 $payload = json_decode($response->get_data(), true); 28 38 … … 30 40 } 31 41 32 public function getArticles( )42 public function getArticles(SearchArticlesForm $form, $orderColumn, $order, $perPage, $offset) 33 43 { 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(); 36 47 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 ]; 41 58 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; 47 139 } 48 140 49 141 public function getStatuses() 50 142 { 51 $response = $this-> getClient()->request(Method::get(),'stages');143 $response = $this->httpClient->get('stages'); 52 144 $payload = json_decode($response->get_data(), true); 53 145 54 146 return array_map(function(array $row) { return WorkflowStatus::fromState($row); }, $payload); 55 147 } 56 57 private function getClient()58 {59 return Client::fromPluginSettings();60 }61 148 } -
easycontent/trunk/app/Implementation/Form/BaseForm.php
r2825766 r2996293 16 16 final public function __construct(DefaultsProvider $defaults) 17 17 { 18 if ( !$this->fieldsConfig) {18 if ($this->fieldsConfig === []) { 19 19 throw new EmptyConfigException; 20 20 } … … 47 47 { 48 48 $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); 49 59 } 50 60 … … 94 104 } 95 105 96 final public function loadFromPost()97 {98 $this->load($_POST);99 }100 101 final public function loadFromGet()102 {103 $this->load($_GET);104 }105 106 106 /** 107 107 * @return bool -
easycontent/trunk/app/Implementation/Http/Client.php
r2825766 r2996293 6 6 use EasyContent\WordPress\Implementation\Http\Exception\NotFoundException; 7 7 use EasyContent\WordPress\Plugin; 8 use Exception; 9 use WP_HTTP_Requests_Response; 8 10 9 11 final class Client … … 11 13 const BASE_URI = EASYCONTENT_ENDPOINT . '/plugin/api/'; 12 14 13 /** @var string $ key */14 private $ key;15 /** @var string $apiKey */ 16 private $apiKey; 15 17 /** @var null|Referer $referer */ 16 18 private $referer; … … 22 24 public function __construct($key, $referer = null) 23 25 { 24 $this-> key = $key;26 $this->apiKey = $key; 25 27 $this->referer = $referer; 26 28 } … … 37 39 38 40 /** 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 /** 39 65 * @param Method $method 40 66 * @param string $uri 41 67 * @param array $payload 42 * @return \WP_HTTP_Requests_Response43 * @throws \Exception68 * @return WP_HTTP_Requests_Response 69 * @throws Exception 44 70 */ 45 71 public function request(Method $method, $uri, array $payload = []) … … 51 77 52 78 if (is_wp_error($response)) { 53 throw new \Exception(implode(PHP_EOL, $response->errors));79 throw new Exception(implode(PHP_EOL, $response->errors)); 54 80 } 55 81 56 /** @var null| \WP_HTTP_Requests_Response $responseObject */82 /** @var null|WP_HTTP_Requests_Response $responseObject */ 57 83 $responseObject = $response['http_response']; 58 84 59 85 if (null === $responseObject) { 60 throw new \Exception('Unknown error during HTTP request');86 throw new Exception('Unknown error during HTTP request'); 61 87 } 62 88 … … 66 92 throw new NotFoundException; 67 93 } elseif ($statusCode < 200 || $statusCode >= 300) { 68 throw new \Exception($response['response']['message'], $statusCode);94 throw new Exception($response['response']['message'], $statusCode); 69 95 } 70 96 … … 82 108 83 109 /** 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> 85 126 */ 86 127 private function buildHeaders() 87 128 { 88 129 $headers = [ 89 'Authorization' => "Bearer {$this->key}",130 'Authorization' => "Bearer $this->apiKey", 90 131 'Content-Type' => 'application/json', 91 132 ]; 92 133 93 if ($this->referer ) {134 if ($this->referer !== null) { 94 135 $headers['Referer'] = $this->referer->asString(); 95 136 } … … 97 138 return $headers; 98 139 } 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 }109 140 } -
easycontent/trunk/app/Pages/Import/ArticlesListTable.php
r2825766 r2996293 5 5 use EasyContent\WordPress\Db\Models\Article; 6 6 use EasyContent\WordPress\Helpers\TimeHelper; 7 use EasyContent\WordPress\Implementation\Entity\RemoteEasyContentStorage; 7 8 use EasyContent\WordPress\Implementation\Form\SearchArticlesForm; 9 use EasyContent\WordPress\Plugin; 8 10 use EasyContent\WordPress\WP_List_Table; 9 11 10 12 final class ArticlesListTable extends WP_List_Table 11 13 { 14 /** @var SearchArticlesForm $form */ 12 15 private $form; 13 16 14 public function __construct(SearchArticlesForm $form = null, $args = [])17 public function __construct(SearchArticlesForm $form, $args = []) 15 18 { 16 19 parent::__construct($args); … … 22 25 $this->_column_headers = [$this->get_columns(), [], $this->get_sortable_columns()]; 23 26 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; 25 32 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); 30 35 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 ]); 34 43 } 35 44 … … 53 62 'updated' => ['updated', false], 54 63 'status' => ['status', false], 55 'last_synced' => ['last_synced', false]56 64 ]; 57 65 } … … 81 89 protected function column_status($item) 82 90 { 91 if (!isset($item['color'])) { 92 return '<i>No data in local cache</i>'; 93 } 94 83 95 // TODO: move styles 84 96 return '<span style="border-radius: 50%; background-color: #' . $item['color'] . '; width: 20px; height: 20px; display: inline-block"> </span> ' … … 88 100 protected function column_last_synced($item) 89 101 { 90 if ( ! $item['sync_time']) {102 if ( ! isset($item['sync_time']) ) { 91 103 return __( 'Never', EASYCONTENT_TXTDOMAIN ); 92 104 } -
easycontent/trunk/app/Source/Api/Entity/Responses/ConnectionResponse.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Source\Api\Entity\Responses; 4 4 5 use EasyContent\WordPress\Source\Api\Entity\Article;6 5 use EasyContent\WordPress\Source\Api\Entity\Category; 7 6 use EasyContent\WordPress\Source\Api\Entity\Entity; … … 14 13 /** @var string $projectName */ 15 14 private $projectName; 16 /** @var array|Article[] $articles */17 private $articles = [];18 15 /** @var array|Category[] $categories */ 19 16 private $categories = []; … … 34 31 ->setAccountName($data) 35 32 ->setProjectName($data) 36 ->setArticles($data)37 33 ->setCategories($data) 38 34 ->setStages($data) … … 77 73 $this->ensureString($data['projectName']); 78 74 $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 $data92 * @return ConnectionResponse93 */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 103 75 return $this; 104 76 } -
easycontent/trunk/app/Source/Entity/CacheCheckResult.php
r2825766 r2996293 7 7 final class CacheCheckResult 8 8 { 9 /** @var array|EntityInterface[] $delete */9 /** @var EntityInterface[] $delete */ 10 10 private $delete; 11 /** @var array|EntityInterface[] $insert */11 /** @var EntityInterface[] $insert */ 12 12 private $insert; 13 /** @var array|EntityInterface[] $checkUpdate */13 /** @var EntityInterface[] $checkUpdate */ 14 14 private $checkUpdate; 15 /** @var array|EntityInterface[] $indexedFreshData */15 /** @var EntityInterface[] $indexedFreshData */ 16 16 private $indexedFreshData; 17 17 18 18 /** 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 22 23 */ 23 24 public function __construct(array $delete, array $insert, array $checkUpdate, array $indexedFreshData) … … 30 31 31 32 /** 32 * @return array|EntityInterface[]33 * @return EntityInterface[] 33 34 */ 34 35 public function getDelete() … … 38 39 39 40 /** 40 * @return array|EntityInterface[]41 * @return EntityInterface[] 41 42 */ 42 43 public function getInsert() … … 46 47 47 48 /** 48 * @return array|EntityInterface[]49 * @return EntityInterface[] 49 50 */ 50 51 public function getCheckUpdate() -
easycontent/trunk/app/Source/Entity/CachedArticle.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Source\Entity; 4 4 5 use EasyContent\WordPress\Source\Api\Entity\Article;6 5 use EasyContent\WordPress\Source\Api\Entity\Entity; 7 6 use EasyContent\WordPress\Source\Api\Entity\EntityInterface; … … 40 39 } 41 40 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 55 41 /** 56 42 * @param array $data -
easycontent/trunk/app/Source/Entity/CachedArticlesStorage.php
r2825766 r2996293 5 5 use EasyContent\WordPress\Source\Exception\CachedArticleNotFoundException; 6 6 7 interface CachedArticlesStorage extends LocalCache7 interface CachedArticlesStorage 8 8 { 9 9 /** … … 26 26 */ 27 27 public function getById($id); 28 29 /** 30 * @param CachedArticle $item 31 * @return void 32 */ 33 public function update($item); 28 34 } -
easycontent/trunk/app/Source/Entity/EasyContentStorage.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Source\Entity; 4 4 5 use EasyContent\WordPress\Implementation\Form\SearchArticlesForm; 5 6 use EasyContent\WordPress\Source\Api\Entity\Category; 6 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;7 7 use EasyContent\WordPress\Source\Api\Entity\Responses\ConnectionResponse; 8 8 use EasyContent\WordPress\Source\Api\Entity\WorkflowStatus; … … 22 22 23 23 /** 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 25 30 */ 26 public function getArticles( );31 public function getArticles(SearchArticlesForm $form, $orderColumn, $order, $perPage, $offset); 27 32 28 33 /** -
easycontent/trunk/app/Source/Entity/WorkflowStatusStorage.php
r2825766 r2996293 25 25 */ 26 26 public function getById($id); 27 28 /**29 * @return array|WorkflowStatus[]30 */31 public function findInUse();32 27 } -
easycontent/trunk/app/Source/Services/CacheUpdater.php
r2825766 r2996293 11 11 /** 12 12 * @param LocalCache $repository 13 * @param array|EntityInterface[] $fetchedItems13 * @param EntityInterface[] $fetchedItems 14 14 * @return void 15 15 */ … … 37 37 38 38 /** 39 * @param array|EntityInterface[] $old40 * @param array|EntityInterface[] $new39 * @param EntityInterface[] $old 40 * @param EntityInterface[] $new 41 41 * @return CacheCheckResult 42 42 */ … … 55 55 56 56 /** 57 * @param array|EntityInterface[] $items58 * @return array |EntityInterface[]57 * @param EntityInterface[] $items 58 * @return array<int, EntityInterface> 59 59 */ 60 60 private function index(array $items) -
easycontent/trunk/app/Source/Services/CategoriesMapper.php
r2825766 r2996293 55 55 56 56 foreach ($categoriesIds as $termId) { 57 if (!isset($mappings[$termId])) { 58 continue; 59 } 60 57 61 if ($mappings[$termId] <= 0) { 58 62 continue; -
easycontent/trunk/app/Source/UseCase/Connect/Handler.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Source\UseCase\Connect; 4 4 5 use EasyContent\WordPress\Source\Api\Entity\Article;6 use EasyContent\WordPress\Source\Entity\CachedArticle;7 use EasyContent\WordPress\Source\Entity\CachedArticlesStorage;8 5 use EasyContent\WordPress\Source\Entity\CategoriesStorage; 9 6 use EasyContent\WordPress\Source\Entity\EasyContentStorage; … … 17 14 private $pluginStorage; 18 15 private $categories; 19 private $articles;20 16 private $statuses; 21 17 private $cacheUpdater; … … 25 21 PluginStorage $pluginStorage, 26 22 CategoriesStorage $categories, 27 CachedArticlesStorage $articles,28 23 WorkflowStatusStorage $statuses 29 24 ) { … … 31 26 $this->pluginStorage = $pluginStorage; 32 27 $this->categories = $categories; 33 $this->articles = $articles;34 28 $this->statuses = $statuses; 35 29 $this->cacheUpdater = new CacheUpdater; … … 55 49 // Update cache of all tables 56 50 $this->cacheUpdater->updateCache($this->categories, $response->getCategories()); 57 $this->cacheUpdater->updateCache($this->articles, $this->convertArticles($response->getArticles()));58 51 $this->cacheUpdater->updateCache($this->statuses, $response->getStages()); 59 52 } 60 61 /**62 * @param array|Article[] $articles63 * @return array|CachedArticle[]64 */65 private function convertArticles(array $articles)66 {67 return array_map(function(Article $article) { return CachedArticle::fromSimple($article); }, $articles);68 }69 53 } -
easycontent/trunk/app/Source/UseCase/RefreshCachedData/Handler.php
r2825766 r2996293 3 3 namespace EasyContent\WordPress\Source\UseCase\RefreshCachedData; 4 4 5 use EasyContent\WordPress\Source\Api\Entity\ImportedArticle;6 use EasyContent\WordPress\Source\Entity\CachedArticle;7 use EasyContent\WordPress\Source\Entity\CachedArticlesStorage;8 5 use EasyContent\WordPress\Source\Entity\CategoriesStorage; 9 6 use EasyContent\WordPress\Source\Entity\EasyContentStorage; … … 15 12 private $remoteRepository; 16 13 private $categories; 17 private $articles;18 14 private $statuses; 19 15 private $cacheUpdater; … … 22 18 EasyContentStorage $remoteRepository, 23 19 CategoriesStorage $categories, 24 CachedArticlesStorage $articles,25 20 WorkflowStatusStorage $statuses 26 21 ) { 27 22 $this->remoteRepository = $remoteRepository; 28 23 $this->categories = $categories; 29 $this->articles = $articles;30 24 $this->statuses = $statuses; 31 25 $this->cacheUpdater = new CacheUpdater; … … 35 29 { 36 30 $categories = $this->remoteRepository->getCategories(); 37 $articles = $this->remoteRepository->getArticles();38 31 $statuses = $this->remoteRepository->getStatuses(); 39 32 40 33 $this->cacheUpdater->updateCache($this->categories, $categories); 41 $this->cacheUpdater->updateCache($this->articles, $this->convertArticles($articles));42 34 $this->cacheUpdater->updateCache($this->statuses, $statuses); 43 35 } 44 45 /**46 * @param array|ImportedArticle[] $articles47 * @return array|CachedArticle[]48 */49 private function convertArticles(array $articles)50 {51 return array_map(function(ImportedArticle $article) { return CachedArticle::fromImported($article); }, $articles);52 }53 36 } -
easycontent/trunk/app/dependencies-config.php
r2825766 r2996293 50 50 [Client::class, 'fromPluginSettings'], 51 51 ], 52 RemoteEasyContentStorage::class => [ 53 [Client::class, 'fromPluginSettings'], 54 DbWorkflowStatusStorage::class, 55 ], 52 56 ConnectHandler::class => [ 53 57 RemoteEasyContentStorage::class, 54 58 DefaultPluginStorage::class, 55 59 DbCategoriesStorage::class, 56 DbCachedArticlesStorage::class,57 60 DbWorkflowStatusStorage::class, 58 61 ], … … 86 89 RemoteEasyContentStorage::class, 87 90 DbCategoriesStorage::class, 88 DbCachedArticlesStorage::class,89 91 DbWorkflowStatusStorage::class, 90 92 ], -
easycontent/trunk/easycontent-wp.php
r2825775 r2996293 4 4 * Plugin URI: https://easycontent.io 5 5 * Description: Imports articles from EasyContent to your wordpress site and exports articles from your wordpress site to EasyContent 6 * Version: 1. 1.26 * Version: 1.2.0 7 7 * Requires at least: 5.0.7 8 8 * Requires PHP: 5.6 … … 21 21 22 22 if ( ! defined( 'EASYCONTENT_PLUGIN_VERSION' ) ) { 23 define( 'EASYCONTENT_PLUGIN_VERSION', '1. 1.2' );23 define( 'EASYCONTENT_PLUGIN_VERSION', '1.2.0' ); 24 24 } 25 25 -
easycontent/trunk/readme.txt
r2825775 r2996293 4 4 Tags: easycontent, easy content, workflow, approval, collaboration, import, export, manage writers, publishing, content flow, editorial, approval process, content tool 5 5 Requires at least: 5.0.7 6 Tested up to: 6. 1.16 Tested up to: 6.4.1 7 7 Requires PHP: 5.6 8 Stable tag: 1. 1.28 Stable tag: 1.2.0 9 9 License: GPL-2.0+ 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 61 61 == Changelog == 62 62 63 = 1.2.0 = 64 * Reworked "Import from EasyContent" page to be able to interact with huge projects 65 63 66 = 1.1.2 = 64 67 * Minor changes -
easycontent/trunk/vendor/autoload.php
r2825766 r2996293 5 5 require_once __DIR__ . '/composer/autoload_real.php'; 6 6 7 return ComposerAutoloaderInitd edf6cdf3e9e2575a2973d3cb52d50d1::getLoader();7 return ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8::getLoader(); -
easycontent/trunk/vendor/composer/autoload_classmap.php
r2825766 r2996293 95 95 'EasyContent\\WordPress\\Rest\\RestManager' => $baseDir . '/app/Rest/RestManager.php', 96 96 'EasyContent\\WordPress\\Singleton' => $baseDir . '/app/Singleton.php', 97 'EasyContent\\WordPress\\Source\\Api\\Entity\\Article' => $baseDir . '/app/Source/Api/Entity/Article.php',98 97 'EasyContent\\WordPress\\Source\\Api\\Entity\\BaseArticle' => $baseDir . '/app/Source/Api/Entity/BaseArticle.php', 99 98 'EasyContent\\WordPress\\Source\\Api\\Entity\\Category' => $baseDir . '/app/Source/Api/Entity/Category.php', -
easycontent/trunk/vendor/composer/autoload_real.php
r2825766 r2996293 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInitd edf6cdf3e9e2575a2973d3cb52d50d15 class ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8 6 6 { 7 7 private static $loader; … … 25 25 require __DIR__ . '/platform_check.php'; 26 26 27 spl_autoload_register(array('ComposerAutoloaderInitd edf6cdf3e9e2575a2973d3cb52d50d1', 'loadClassLoader'), true, true);27 spl_autoload_register(array('ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8', 'loadClassLoader'), true, true); 28 28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); 29 spl_autoload_unregister(array('ComposerAutoloaderInitd edf6cdf3e9e2575a2973d3cb52d50d1', 'loadClassLoader'));29 spl_autoload_unregister(array('ComposerAutoloaderInitdf4fcb7f8c54e88af0fcf9883fd5bea8', 'loadClassLoader')); 30 30 31 31 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); … … 33 33 require __DIR__ . '/autoload_static.php'; 34 34 35 call_user_func(\Composer\Autoload\ComposerStaticInitd edf6cdf3e9e2575a2973d3cb52d50d1::getInitializer($loader));35 call_user_func(\Composer\Autoload\ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::getInitializer($loader)); 36 36 } else { 37 37 $map = require __DIR__ . '/autoload_namespaces.php'; -
easycontent/trunk/vendor/composer/autoload_static.php
r2825766 r2996293 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInitd edf6cdf3e9e2575a2973d3cb52d50d17 class ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 118 118 'EasyContent\\WordPress\\Rest\\RestManager' => __DIR__ . '/../..' . '/app/Rest/RestManager.php', 119 119 'EasyContent\\WordPress\\Singleton' => __DIR__ . '/../..' . '/app/Singleton.php', 120 'EasyContent\\WordPress\\Source\\Api\\Entity\\Article' => __DIR__ . '/../..' . '/app/Source/Api/Entity/Article.php',121 120 'EasyContent\\WordPress\\Source\\Api\\Entity\\BaseArticle' => __DIR__ . '/../..' . '/app/Source/Api/Entity/BaseArticle.php', 122 121 'EasyContent\\WordPress\\Source\\Api\\Entity\\Category' => __DIR__ . '/../..' . '/app/Source/Api/Entity/Category.php', … … 195 194 { 196 195 return \Closure::bind(function () use ($loader) { 197 $loader->prefixLengthsPsr4 = ComposerStaticInitd edf6cdf3e9e2575a2973d3cb52d50d1::$prefixLengthsPsr4;198 $loader->prefixDirsPsr4 = ComposerStaticInitd edf6cdf3e9e2575a2973d3cb52d50d1::$prefixDirsPsr4;199 $loader->classMap = ComposerStaticInitd edf6cdf3e9e2575a2973d3cb52d50d1::$classMap;196 $loader->prefixLengthsPsr4 = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$prefixLengthsPsr4; 197 $loader->prefixDirsPsr4 = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$prefixDirsPsr4; 198 $loader->classMap = ComposerStaticInitdf4fcb7f8c54e88af0fcf9883fd5bea8::$classMap; 200 199 201 200 }, null, ClassLoader::class); -
easycontent/trunk/views/admin/pages/import.php
r2825766 r2996293 3 3 * @var View $this 4 4 * @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 7 6 * @var SearchArticlesForm $searchForm 8 7 */ … … 27 26 28 27 echo (new View)->render('admin/pages/import/table-filters', [ 29 'statuses InUse' => $statusesInUse,28 'statuses' => $statuses, 30 29 'searchForm' => $searchForm, 31 30 ]); … … 40 39 </button> 41 40 42 <?php if ( $ workflowStages) : ?>41 <?php if ( $statuses !== [] ) : ?> 43 42 <?= esc_html__( 'On import, change EasyContent status to', EASYCONTENT_TXTDOMAIN ) ?> 44 43 … … 46 45 <option value=""><?= esc_html__( "Don't change status", EASYCONTENT_TXTDOMAIN ) ?></option> 47 46 48 <?php foreach ( $ workflowStages as $stage ) : ?>47 <?php foreach ( $statuses as $stage ) : ?> 49 48 <option value="<?= esc_attr( $stage->getId() ) ?>"> 50 49 <?= esc_html( $stage->getName() ) ?> … … 62 61 </button> 63 62 64 <?php if ( $ workflowStages) : ?>63 <?php if ( $statuses !== [] ) : ?> 65 64 <?= esc_html__( 'On import, change EasyContent status to', EASYCONTENT_TXTDOMAIN ) ?> 66 65 … … 68 67 <option value=""><?= esc_html__( "Don't change status", EASYCONTENT_TXTDOMAIN ) ?></option> 69 68 70 <?php foreach ( $ workflowStages as $stage ) : ?>69 <?php foreach ( $statuses as $stage ) : ?> 71 70 <option value="<?= esc_attr( $stage->getId() ) ?>"> 72 71 <?= esc_html( $stage->getName() ) ?> -
easycontent/trunk/views/admin/pages/import/table-filters.php
r2825766 r2996293 2 2 /** 3 3 * @var EasyContent\WordPress\View $this 4 * @var array|EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statusesInUse4 * @var EasyContent\WordPress\Source\Api\Entity\WorkflowStatus[] $statuses 5 5 * @var EasyContent\WordPress\Implementation\Form\SearchArticlesForm $searchForm 6 6 */ … … 19 19 value="<?= esc_attr($searchForm->getArticleName()) ?>"> 20 20 21 <?php if ($statuses InUse) : ?>21 <?php if ($statuses !== []) : ?> 22 22 <label for="ec-workflow-stage" class="screen-reader-text"><?= esc_html__( 'Status', EASYCONTENT_TXTDOMAIN ) ?></label> 23 23 <select name="<?= esc_attr(sprintf('%s[%s]', $searchForm::NAME, $searchForm::FIELD_WORKFLOW_STATUS_ID)) ?>" id="ec-workflow-stage"> … … 26 26 </option> 27 27 28 <?php foreach ($statuses InUseas $status) : ?>28 <?php foreach ($statuses as $status) : ?> 29 29 <option value="<?= esc_attr($status->getId()) ?>" <?php selected($searchForm->getStatusId(), $status->getId()) ?>> 30 30 <?= esc_html($status->getName()) ?>
Note: See TracChangeset
for help on using the changeset viewer.