Skip to content

Commit

Permalink
core upgrade progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Anderson committed Oct 10, 2018
1 parent ce9d296 commit 27f0693
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Requirements

* SilverStripe 3.0
* SilverStripe 4.0

## Documentation

Expand Down
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php

4 changes: 2 additions & 2 deletions _config/routes.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Name: googleshoppingfeedroutes
---
Director:
SilverStripe\Control\Director:
rules:
'shoppingfeed.xml': 'GoogleShoppingFeedController'
'shoppingfeed.xml': 'ilateral\SilverStripe\GoogleShoppingFeed\Control\GoogleShoppingFeedController'
2 changes: 1 addition & 1 deletion _config/shoppingfeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ After: '#catalogueconfig'
---
SilverCommerce\CatalogueAdmin\Model\CatalogueProduct:
extensions:
ilateral\SilverStripe\GoogleShoppingFeed\extensions\Extension
- ilateral\SilverStripe\GoogleShoppingFeed\Extensions\Extension

File renamed without changes.
6 changes: 3 additions & 3 deletions src/.upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mappings:
GoogleShoppingFeedExtension: ilateral\SilverStripe\GoogleShoppingFeed\extensions\Extension
GoogleProductCategory: ilateral\SilverStripe\GoogleShoppingFeed\model\GoogleProductCategory
GoogleShoppingFeedExtension: ilateral\SilverStripe\GoogleShoppingFeed\Extensions\Extension
GoogleProductCategory: ilateral\SilverStripe\GoogleShoppingFeed\Model\GoogleProductCategory
GoogleShoppingFeed: ilateral\SilverStripe\GoogleShoppingFeed\GoogleShoppingFeed
GoogleShoppingFeedController: ilateral\SilverStripe\GoogleShoppingFeed\controllers\GoogleShoppingFeedController
GoogleShoppingFeedController: ilateral\SilverStripe\GoogleShoppingFeed\Control\GoogleShoppingFeedController
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ilateral\SilverStripe\GoogleShoppingFeed\controllers;
namespace ilateral\SilverStripe\GoogleShoppingFeed\Control;

use NumberFormatter;
use SilverStripe\i18n\i18n;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function index()
'noindex'
);

$items = GoogleShoppingFeed::get_items();
$items = GoogleShoppingFeed::getItems();

$currency = new NumberFormatter(i18n::get_locale(), NumberFormatter::CURRENCY);

Expand Down
17 changes: 6 additions & 11 deletions src/extensions/Extension.php → src/Extensions/Extension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ilateral\SilverStripe\GoogleShoppingFeed\extensions;
namespace ilateral\SilverStripe\GoogleShoppingFeed\Extensions;

use SilverStripe\Assets\Image;
use SilverStripe\ORM\ArrayList;
Expand All @@ -14,6 +14,7 @@
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use TractorCow\AutoComplete\AutoCompleteField;
use ilateral\SilverStripe\GoogleShoppingFeed\Model\GoogleProductCategory;


class Extension extends DataExtension
Expand All @@ -32,9 +33,9 @@ class Extension extends DataExtension
];

private static $has_one = [
"ShoppingPrimaryImage" => "Image",
"ShoppingAdditionalImage" => "Image",
"GoogleProductCategory" => "GoogleProductCategory"
"ShoppingPrimaryImage" => Image::class,
"ShoppingAdditionalImage" => Image::class,
"GoogleProductCategory" => GoogleProductCategory::class
];

/**
Expand Down Expand Up @@ -172,9 +173,7 @@ public function addCMSFieldsToTabset($tabset)
'GoogleProductCategoryID',
$this->owner->fieldLabel("GoogleProductCategory"),
'',
null,
null,
'GoogleProductCategory',
GoogleProductCategory::class,
'Title'
),
UploadField::create("ShoppingPrimaryImage")
Expand Down Expand Up @@ -202,8 +201,6 @@ public function hasCMSSettingsFields()
*/
public function updateSettingsFields(FieldList $fields)
{
var_dump("i'm here!");
exit;
if($this->owner->hasCMSSettingsFields()) {
$tabset = $fields->findOrMakeTab('Root.Settings');

Expand All @@ -221,8 +218,6 @@ public function updateSettingsFields(FieldList $fields)
*/
public function updateCMSFields(FieldList $fields)
{
var_dump("i'm here!");
exit;
if (!$this->owner->hasCMSSettingsFields()) {
$tabset = $fields->findOrMakeTab('Root.Settings');

Expand Down
29 changes: 22 additions & 7 deletions src/GoogleShoppingFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ilateral\SilverStripe\GoogleShoppingFeed;

use Product;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Core\Config\Config;
Expand Down Expand Up @@ -66,7 +67,7 @@ class GoogleShoppingFeed
public static function register_dataobject($className)
{
if (!self::is_registered($className)) {
$className::add_extension('GoogleShoppingFeedExtension');
$className::add_extension(Extension::class);

self::$dataobjects[] = $className;
}
Expand Down Expand Up @@ -130,20 +131,20 @@ public static function clear_registered_dataobjects()
*
* @return ArrayList
*/
public static function get_items()
public static function getItems()
{
$output = new ArrayList();
$search_filter = Config::inst()->get('GoogleShoppingFeed', 'use_show_in_search');
$disabled_filter = Config::inst()->get('GoogleShoppingFeed', 'use_disabled');
$search_filter = Config::inst()->get(__CLASS__, 'use_show_in_search');
$disabled_filter = Config::inst()->get(__CLASS__, 'use_disabled');
$filter = array();

// todo migrate to extension hook or DI point for other modules to
foreach (self::$dataobjects as $class) {
if ($class == "SiteTree") {
if ($class == SiteTree::class) {
$search_filter = ($search_filter) ? "\"ShowInSearch\" = 1" : "";

$instances = Versioned::get_by_stage('SiteTree', 'Live', $search_filter);
} elseif ($class == "Product") {
} elseif ($class == Product::class) {
$instances = $class::get();

if ($disabled_filter) {
Expand All @@ -164,6 +165,20 @@ public static function get_items()

return $output;
}

/**
* Static interface to instance level ->getItems() for backward compatibility.
*
* @param string
* @param int
*
* @return ArrayList
* @deprecated Please create an instance and call ->getSitemaps() instead.
*/
public static function get_items()
{
return static::inst()->getItems();
}

/**
* Returns the string frequency of edits for a particular dataobject class.
Expand Down Expand Up @@ -191,6 +206,6 @@ public static function get_frequency_for_class($class)
*/
public static function enabled()
{
return (Config::inst()->get('GoogleShoppingFeed', 'enabled', Config::INHERITED));
return (Config::inst()->get(self::class, 'enabled'));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ilateral\SilverStripe\GoogleShoppingFeed\model;
namespace ilateral\SilverStripe\GoogleShoppingFeed\Model;

use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -56,7 +56,7 @@ public function getGoogleCategories()
{
// Get a list of Google Categories from the
// product file.
$file = BASE_PATH . "/googleshoppingfeed/thirdparty/google_product_taxonomy.txt";
$file = __DIR__ . "../../thirdparty/google_product_taxonomy.txt";
$fopen = fopen($file, 'r');
$fread = fread($fopen, filesize($file));
fclose($fopen);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/GoogleShoppingFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testGetItems()
{
GoogleShoppingFeed::register_dataobject("GoogleShoppingFeedTest_Product", '');

$items = GoogleShoppingFeed::get_items('GoogleShoppingFeedTest_Product', 1);
$items = GoogleShoppingFeed::getItems('GoogleShoppingFeedTest_Product', 1);
$this->assertEquals(3, $items->count());
}

Expand Down

0 comments on commit 27f0693

Please sign in to comment.