Skip to content

Commit

Permalink
Merge pull request #14 from craftpulse/develop-v4
Browse files Browse the repository at this point in the history
feat: support for assets
  • Loading branch information
cookie10codes authored Dec 1, 2023
2 parents 3f6ef98 + e2e2bec commit d2eaa03
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 41 deletions.
45 changes: 34 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,62 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 5.1.0 - 2023-12-01

### Added

- Support for Assets

## 5.0.1 - 2023-11-22

### Changed
- Changed the handling of the document deletion for mutli sites

- Changed the handling of the document deletion for mutli sites

## 5.0.0 - 2023-03-13 / Official release

### Added
- Docs for the official release
- Seperate typesense logging

- Docs for the official release
- Seperate typesense logging

### Changed
- Move the deletion of the collection into the sync if it's a flush #7

- Move the deletion of the collection into the sync if it's a flush #7

## 4.0.2 - 2022-11-04

### Added
- Added the possibility to handle save for all the types inside of the section

- Added the possibility to handle save for all the types inside of the section

## 4.0.1 - 2022-10-25

### Fix
- Fixed: the project rebuild command was failing because of project config settings, these were disabled since we don't use them yet

- Fixed: the project rebuild command was failing because of project config settings, these were disabled since we don't use them yet

## 4.0.0 - 2022-10-06

### Added
- Added: A sync console command

- Added: A sync console command

## 4.0.0-beta.3 - 2022-09-19

### Changed
- Changed: disabled the before routing fetch to check for scheduled posts

- Changed: disabled the before routing fetch to check for scheduled posts

## 4.0.0-beta.2 - 2022-09-19

### Added
- Added: Delete the document when setting an enabled entry to disable [#6](https://github.com/percipioglobal/craft-typesense/issues/6)
- Added: Create the document when a scheduled post becomes active [#9](https://github.com/percipioglobal/craft-typesense/issues/9)

- Added: Delete the document when setting an enabled entry to disable [#6](https://github.com/percipioglobal/craft-typesense/issues/6)
- Added: Create the document when a scheduled post becomes active [#9](https://github.com/percipioglobal/craft-typesense/issues/9)

## 4.0.0-beta.1 - 2022-08-21

### Added
- Added support for Craft 4

- Added support for Craft 4
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Typesense plugin for Craft CMS 4.x

Craft Plugin that synchronises with Typesense. Visit our [Demo](https://typesense.percipio.london/demo) to see the Craft Typesense plugin in action. You can read our [docs](https://typesense.percipio.london/docs/about) to setup your project. Need more help with the setup? Follow our blogpost "[Setup the Typsesense plugin with Typesense Cloud with javascript](https://percipio.london/blog/craftcms-plugin-typsesense)"
Craft Plugin that synchronises with Typesense.

<!-- Visit our [Demo](https://typesense.percipio.london/demo) to see the Craft Typesense plugin in action. You can read our [docs](https://typesense.percipio.london/docs/about) to setup your project. Need more help with the setup? Follow our blogpost "[Setup the Typsesense plugin with Typesense Cloud with javascript](https://percipio.london/blog/craftcms-plugin-typsesense)" -->

![Screenshot](resources/img/plugin-logo.png)

Expand All @@ -12,15 +14,15 @@ This plugin requires Craft CMS 4.0.0 or later.

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:
1. Open your terminal and go to your Craft project:

cd /path/to/project

2. Then tell Composer to load the plugin:
2. Then tell Composer to load the plugin:

composer require craftpulse/craft-typesense

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Typesense.
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Typesense.

## Typesense Overview

Expand Down Expand Up @@ -77,6 +79,7 @@ After copy and paste the config.php into your own config folder and name it type
```

By default, Craft CMS doesn't fire an event after updating a status when a scheduled post goes out. Therefore we provide a console command that you can attach to your cron jobs. The command checks if there are entries that are scheduled to go out today and if they haven't been updated after that date

```
./craft typesense/default/update-scheduled-posts
```
Expand All @@ -89,6 +92,6 @@ By default, Craft CMS doesn't fire an event after updating a status when a sched

Some things to do, and ideas for potential features:

* Release it
- Release it

Brought to you by [percipiolondon](https://percipio.london)
Brought to you by [craftpulse](https://github.com/craftpulse)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "craftpulse/craft-typesense",
"description": "Craft Plugin that synchronises with Typesense",
"type": "craft-plugin",
"version": "5.0.1",
"version": "5.1.0",
"keywords": [
"craft",
"cms",
Expand Down
69 changes: 52 additions & 17 deletions src/controllers/CollectionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CollectionsController extends Controller
* @throws InvalidConfigException
* @throws ForbiddenHttpException
*/
public function init() :void
public function init(): void
{
parent::init();

Expand Down Expand Up @@ -91,19 +91,53 @@ public function actionCollections(): Response
$indexes = Typesense::$plugin->getSettings()->collections;

foreach ($indexes as $index) {
$entry = $index->criteria->one();
$section = $entry->section ?? null;

if ($section) {
$variables['sections'][] = [
'id' => $section->id,
'name' => $section->name,
'handle' => $section->handle,
'type' => $entry->type->handle,
'entryCount' => $index->criteria->count(),
'index' => $index->indexName,
];
$element = $index->criteria->one();

switch ($index->elementType) {
case 'craft\elements\Asset':
$volume = $element->getVolume() ?? null;

if ($volume) {
$variables['sections'][] = [
'id' => 1,
'name' => $volume->name,
'handle' => $volume->handle,
'type' => 'Asset: ' . $volume->handle,
'entryCount' => $index->criteria->count(),
'index' => $index->indexName,
];
}
break;

case 'craft\elements\Entry':
$section = $element->section ?? null;

if ($section) {
$variables['sections'][] = [
'id' => $section->id,
'name' => $section->name,
'handle' => $section->handle,
'type' => 'Entry: ' . $element->type->handle,
'entryCount' => $index->criteria->count(),
'index' => $index->indexName,
];
}
break;
}

// Craft::dd($element);
// $section = $entry->section ?? null;

// if ($section) {
// $variables['sections'][] = [
// 'id' => $section->id,
// 'name' => $section->name,
// 'handle' => $section->handle,
// 'type' => $entry->type->handle,
// 'entryCount' => $index->criteria->count(),
// 'index' => $index->indexName,
// ];
// }
}

$variables['csrf'] = [
Expand Down Expand Up @@ -337,7 +371,7 @@ public function actionDocuments(): Response|string

// Render the template
return $this->renderTemplate('typesense/documents/index', $variables);
// $request = Craft::$app->getRequest();
// $request = Craft::$app->getRequest();
// $index = $request->getBodyParam('index');
//
// if (isset(Typesense::$plugin->getClient()->client()->collections[$index])) {
Expand Down Expand Up @@ -367,11 +401,11 @@ public function actionDocument(int $sectionId): Response|string
$section = $entry->section ?? null;

if ($section->id === $sectionId) {
$templateTitle = Craft::t('typesense', 'Collections of '.$section->name);
$templateTitle = Craft::t('typesense', 'Collections of ' . $section->name);
$documents = $this->asJson(Typesense::$plugin->getClient()->client()->collections[$index->indexName]->documents->export());

if ($documents) {
$documents = explode("\n",$documents->data);
$documents = explode("\n", $documents->data);
foreach ($documents as $document) {
$variables['documents'][] = Json::decode($document);
}
Expand Down Expand Up @@ -456,7 +490,8 @@ public function actionRetrieveCollection()
return $this->asJson(Typesense::$plugin->getClient()->client()->collections[$index]->retrieve());
}

private function _sortDocuments($a, $b) {
private function _sortDocuments($a, $b)
{
if ($a['post_date_timestamp'] == $b['post_date_timestamp']) {
return 0;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d2eaa03

Please sign in to comment.