Skip to content

Commit

Permalink
Revert "PHPstan level 1"
Browse files Browse the repository at this point in the history
This reverts commit 9e86841.
  • Loading branch information
janhenckens committed Oct 11, 2023
1 parent 2d2dd81 commit 6a1b6c3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 43 deletions.
8 changes: 2 additions & 6 deletions src/SeoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,10 @@ private function _registerCustomElements()
{
$elements = [];
if (Craft::$app->getPlugins()->isPluginEnabled('calendar')) {
if(class_exists('Solspace\Calendar\Elements\Event')) {
$elements[] = \Solspace\Calendar\Elements\Event::class;
}
$elements[] = \Solspace\Calendar\Elements\Event::class;
}
if (Craft::$app->getPlugins()->isPluginEnabled('commerce')) {
if(class_exists('craft\commerce\elements\Product')) {
$elements[] = \craft\commerce\elements\Product::class;
}
$elements[] = \craft\commerce\elements\Product::class;
}

if ($elements) {
Expand Down
3 changes: 1 addition & 2 deletions src/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ class MigrateController extends Controller
public $metaTitle;
public $metaDescription;

public function options($actionId): array
public function options($actionId)
{
switch ($actionId) {
case 'ether':
return ['oldHandle', 'newHandle', 'siteId', 'titleSeperator'];
case 'fields':
return ['fieldHandle', 'metaTitle', 'metaDescription'];
}
return [];
}

public function actionEther()
Expand Down
1 change: 1 addition & 0 deletions src/controllers/CpApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function actionNotFound()
$query->orderBy($key . " " . $direction);
$rows = [];

$allSites = Craft::$app->getSites()->getAllSites();

$formatter = Craft::$app->getFormatter();
foreach ($query->all() as $row) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/RedirectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private function getHeaders($reader)
{
// Support for league/csv v8 with a header
try {
return $reader->fetchOne(0);
return $csv->fetchOne(0);
} catch (\Throwable $e) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/jobs/MigrateFieldDataJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MigrateFieldDataJob extends BaseJob
public $metaDescription;


public function init(): void
public function init()
{
if (!$this->fieldHandle) {
throw new InvalidFieldException('Field handle not provided');
Expand All @@ -26,7 +26,7 @@ public function init(): void
}


public function execute($queue): void
public function execute($queue)
{
$model = new SeoFieldModel();
if ($this->entry->metaTitle) {
Expand Down
23 changes: 23 additions & 0 deletions src/services/NotFoundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ public function handleNotFoundException()
$this->handleNotFound($request, $site);
}

public function getAllNotFound($orderBy, $siteHandle = null, $handled)
{
$data = [];
$query = NotFoundRecord::find();
$query->orderBy("$orderBy DESC, dateLastHIT DESC");
$query->where(['in', 'siteId', Craft::$app->getSites()->getEditableSiteIds()]);
if ($siteHandle) {
$site = Craft::$app->getSites()->getSiteByHandle($siteHandle);
$query->andWhere(['siteId' => $site->id]);
}

if ($handled !== "all") {
$query->andWhere(Db::parseParam('handled', $handled));
}

foreach ($query->all() as $record) {
$model = new NotFoundModel();
$model->setAttributes($record->getAttributes());
$data[] = $model;
}
return $data;
}

public function handleNotFound(Request $request, Site $site)
{
try {
Expand Down
15 changes: 5 additions & 10 deletions src/services/SitemapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ public function getSitemapData($siteId, $type, $sectionId)
$data = [];
switch ($type) {
case 'product':
if(class_exists('craft\commerce\elements\Product')) {
$data = Product::findAll([
'siteId' => $siteId,
'typeId' => $sectionId,
'orderBy' => 'dateUpdated DESC',
]);
}
$data = Product::findAll([
'siteId' => $siteId,
'typeId' => $sectionId,
'orderBy' => 'dateUpdated DESC',
]);
break;
case 'category':
$data = Category::findAll([
Expand Down Expand Up @@ -281,9 +279,7 @@ private function _addProductsToIndex($productTypes, $site)
{
$data = [];
foreach ($productTypes as $id => $settings) {
/** @phpstan-ignore-next-line */
$type = Commerce::getInstance()->productTypes->getProductTypeById($id);
/** @phpstan-ignore-next-line */
$entry = Product::findOne(['typeId' => $type->id, 'orderBy' => 'dateUpdated DESC']);
if ($entry) {
$data[] = implode('', $this->_addItemToIndex($site, $type, $entry));
Expand Down Expand Up @@ -350,7 +346,6 @@ private function _shouldRenderProducts($sitemapSettings)

$shouldRenderProducts = array_filter($sitemapSettings['product'], function($productType) use ($sitemapSettings) {
if (isset($sitemapSettings['product'][$productType]['enabled'])) {
/** @phpstan-ignore-next-line */
$productTypeService = new ProductTypes();
$site = Craft::$app->getSites()->getCurrentSite();
foreach ($productTypeService->getProductTypeSites($productType) as $productTypeSite) {
Expand Down
42 changes: 20 additions & 22 deletions src/services/migrate/Ether.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,34 @@ public function migrate($oldHandle = 'seo', $newHandle = 'newSeo', $siteId = nul

private function migrateContent(Entry $entry, $field, $newHandle)
{
if (class_exists("ether\seo\models\data\SeoData") && class_exists("ether\seo\models\data\SocialData")) {
if ($entry->$field && get_class($entry->$field) === 'ether\seo\models\data\SeoData') {
/** @var SeoData $oldField */
$oldField = $entry->$field;
$newField = new SeoFieldModel();
$newField->metaTitle = $this->getTitle($oldField);
$newField->metaDescription = $this->getMarkup($oldField->getDescription());
if ($entry->$field && get_class($entry->$field) === 'ether\seo\models\data\SeoData') {
/** @var SeoData $oldField */
$oldField = $entry->$field;
$newField = new SeoFieldModel();
$newField->metaTitle = $this->getTitle($oldField);
$newField->metaDescription = $this->getMarkup($oldField->getDescription());

/** @var SocialData $facebook */
$facebook = $oldField->social['facebook'];
$newField->facebookTitle = $this->removeSeperator($facebook->title);
$newField->facebookDescription = $this->getMarkup($facebook->description);
$newField->facebookImage = [(int)$facebook->imageId];
/** @var SocialData $facebook */
$facebook = $oldField->social['facebook'];
$newField->facebookTitle = $this->removeSeperator($facebook->title);
$newField->facebookDescription = $this->getMarkup($facebook->description);
$newField->facebookImage = [(int)$facebook->imageId];

/** @var SocialData $twitter */
$twitter = $oldField->social['twitter'];
$newField->twitterTitle = $this->removeSeperator($twitter->title);
$newField->twitterDescription = $this->getMarkup($twitter->description);
$newField->twitterImage = [(int)$twitter->imageId];
/** @var SocialData $twitter */
$twitter = $oldField->social['twitter'];
$newField->twitterTitle = $this->removeSeperator($twitter->title);
$newField->twitterDescription = $this->getMarkup($twitter->description);
$newField->twitterImage = [(int)$twitter->imageId];

$entry->setFieldValue($newHandle, $newField);
$entry->setFieldValue($newHandle, $newField);

if (!Craft::$app->getElements()->saveElement($entry)) {
echo "Error updating '$entry->title'";
}
if (!Craft::$app->getElements()->saveElement($entry)) {
echo "Error updating '$entry->title'";
}
}
}

private function getTitle($data)
private function getTitle(SeoData $data)
{
if (count($data->titleRaw)) {
$oldTitle = $data->titleRaw[1];
Expand Down

0 comments on commit 6a1b6c3

Please sign in to comment.