Skip to content

Commit

Permalink
Update plugin to Craft 4
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbushnell committed Jul 5, 2022
1 parent f29dd39 commit a119eef
Show file tree
Hide file tree
Showing 10 changed files with 1,568 additions and 1,016 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "trendyminds/algolia",
"description": "Easily pull search results from Algolia into your Craft CMS website",
"type": "craft-plugin",
"version": "3.1.0",
"version": "4.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,9 +22,8 @@
}
],
"require": {
"php": ">=7.3",
"craftcms/cms": "^3.5.0",
"illuminate/collections": "^8.83",
"php": "^8.0.2",
"craftcms/cms": "^4.0.0",
"algolia/algoliasearch-client-php": "^3.2"
},
"autoload": {
Expand Down
2,482 changes: 1,544 additions & 938 deletions composer.lock

Large diffs are not rendered by default.

45 changes: 4 additions & 41 deletions src/Algolia.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand All @@ -15,12 +15,9 @@
use trendyminds\algolia\models\Settings;

use Craft;
use craft\base\Model;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\web\UrlManager;
use craft\web\twig\variables\CraftVariable;
use craft\events\RegisterUrlRulesEvent;

use yii\base\Event;

Expand Down Expand Up @@ -49,7 +46,7 @@ class Algolia extends Plugin
/**
* @var string
*/
public $schemaVersion = '2.0.0';
public string $schemaVersion = '2.0.0';

// Public Methods
// =========================================================================
Expand All @@ -62,22 +59,6 @@ public function init()
parent::init();
self::$plugin = $this;

Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function (RegisterUrlRulesEvent $event) {
$event->rules['siteActionTrigger1'] = 'algolia/default';
}
);

Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
$event->rules['cpActionTrigger1'] = 'algolia/default/do-something';
}
);

Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
Expand All @@ -87,24 +68,6 @@ function (Event $event) {
$variable->set('algolia', AlgoliaVariable::class);
}
);

Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
}
}
);

Craft::info(
Craft::t(
'algolia',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}

// Protected Methods
Expand All @@ -113,7 +76,7 @@ function (PluginEvent $event) {
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): ?Model
{
return new Settings();
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand All @@ -15,6 +15,7 @@
use Craft;
use craft\web\Controller;
use craft\helpers\Json;
use craft\web\Response;

/**
* @author TrendyMinds
Expand All @@ -32,15 +33,15 @@ class DefaultController extends Controller
* The actions must be in 'kebab-case'
* @access protected
*/
protected $allowAnonymous = ['search', 'browse', 'multiple-queries'];
protected array|int|bool $allowAnonymous = ['search', 'browse', 'multiple-queries'];

// Public Methods
// =========================================================================

/**
* @return mixed
*/
public function actionSearch()
public function actionSearch(): Response
{
$this->requirePostRequest();

Expand All @@ -58,7 +59,7 @@ public function actionSearch()
/**
* @return mixed
*/
public function actionMultipleQueries()
public function actionMultipleQueries(): Response
{
$this->requirePostRequest();

Expand All @@ -72,7 +73,7 @@ public function actionMultipleQueries()
/**
* @return mixed
*/
public function actionBrowse()
public function actionBrowse(): Response
{
$this->requirePostRequest();

Expand Down
8 changes: 4 additions & 4 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand Down Expand Up @@ -28,16 +28,16 @@ class Settings extends Model
/**
* @var string
*/
public $applicationId = '';
public $apiKey = '';
public string $applicationId = '';
public string $apiKey = '';

// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
['applicationId', 'string'],
Expand Down
7 changes: 4 additions & 3 deletions src/services/AlgoliaService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand All @@ -15,6 +15,7 @@

use Craft;
use craft\base\Component;
use craft\helpers\App;

/**
* @author TrendyMinds
Expand All @@ -29,8 +30,8 @@ class AlgoliaService extends Component
// =========================================================================
function __construct()
{
$applicationId = Craft::parseEnv(Algolia::$plugin->getSettings()->applicationId);
$apiKey = Craft::parseEnv(Algolia::$plugin->getSettings()->apiKey);
$applicationId = App::parseEnv(Algolia::$plugin->getSettings()->applicationId);
$apiKey = App::parseEnv(Algolia::$plugin->getSettings()->apiKey);

$this->client = SearchClient::create($applicationId, $apiKey);
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/settings.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# @var craft \craft\web\twig\variables\CraftVariable #}
{#
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Algolia Settings.twig
*
Expand Down
18 changes: 0 additions & 18 deletions src/translations/en/algolia.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/variables/AlgoliaVariable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Algolia plugin for Craft CMS 3.x
* Algolia plugin for Craft CMS 4.x
*
* Easily pull search results from Algolia into your Craft CMS website
*
Expand Down

0 comments on commit a119eef

Please sign in to comment.