Skip to content

Commit

Permalink
Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
k-samuel committed Aug 26, 2017
1 parent 3d04bd6 commit 1938f31
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php
class Dvelum_Frontend_Sitemap_Controller extends Frontend_Controller
namespace Dvelum\App\Frontend\Sitemap;

use Dvelum\App\Frontend;
use Dvelum\Sitemap;
use Dvelum\Config;

class Controller extends Frontend\Controller
{
public function indexAction()
{
$curCode = Request::getInstance()->getPart(1);
$sitemap = new Dvelum_Sitemap($this->_router);
$sitemap->setUrl(Request::url([$this->_router->findUrl('dvelum_sitemap')],false));
$curCode = $this->request->getPart(1);
$sitemap = new Sitemap($this->router);
$sitemap->setUrl($this->request->url([$this->router->findUrl('dvelum_sitemap')],false));

$siteMapAdapters = Config::storage()->get('sitemap.php');

Expand All @@ -25,8 +31,8 @@ public function indexAction()
$xml = $sitemap->getIndexXml();
}

header('Content-type: text/xml; charset=utf-8');
Response::put($xml);
Application::close();
$this->response->header('Content-type: text/xml; charset=utf-8');
$this->response->put($xml);
$this->response->send();
}
}
21 changes: 14 additions & 7 deletions classes/Dvelum/Sitemap.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<?php
class Dvelum_Sitemap
namespace Dvelum;

use Dvelum\App\Router\RouterInterface;
use Dvelum\Request;
use Dvelum\Sitemap\AbstractAdapter;

class Sitemap
{
protected $adapters = [];
protected $url = '/sitemap.xml';
protected $host = '127.0.0.1';
protected $scheme = 'http://';
/**
* @var Router
* @var RouterInterface
*/
protected $router;

public function __construct(Router $router)
public function __construct(RouterInterface $router)
{
$this->host = Request::server('HTTP_HOST', 'string', '');
$request = Request::factory();
$this->host = $request->server('HTTP_HOST', 'string', '');
$this->router = $router;
if(Request::isHttps()){
if($request->isHttps()){
$this->scheme = 'https://';
}
}
Expand All @@ -31,9 +38,9 @@ public function setUrl($url)
/**
* Add sitemap generator
* @param $code
* @param Dvelum_Sitemap_Adapter $adapter
* @param AbstractAdapter $adapter
*/
public function addAdapter($code, Dvelum_Sitemap_Adapter $adapter)
public function addAdapter($code, AbstractAdapter $adapter)
{
$adapter->setRouter($this->router);
$adapter->setScheme($this->scheme);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php
abstract class Dvelum_Sitemap_Adapter
namespace Dvelum\Sitemap;

use Dvelum\App\Router\RouterInterface;

abstract class AbstractAdapter
{
const CHANGEFREQ_HOURLY = 'hourly';
const CHANGEFREQ_DAILY = 'daily';
Expand All @@ -12,7 +16,7 @@ abstract class Dvelum_Sitemap_Adapter
protected $scheme = 'http://';

/**
* @var Router
* @var RouterInterface
*/
protected $router;

Expand All @@ -35,9 +39,9 @@ public function setHost($host)
}

/**
* @param Router $router
* @param RouterInterface $router
*/
public function setRouter(Router $router)
public function setRouter(RouterInterface $router)
{
$this->router = $router;
}
Expand Down
65 changes: 65 additions & 0 deletions classes/Dvelum/Sitemap/Adapter/Pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* DVelum project https://github.com/dvelum/dvelum
* Copyright (C) 2011-2017 Kirill Yegorov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Dvelum\Sitemap\Adapter;

use Dvelum\Orm\Model;
use Dvelum\Request;
use Dvelum\Response;
use Dvelum\Sitemap\AbstractAdapter;

class Pages extends AbstractAdapter
{
public function getItemsXML()
{
$pagesModel = Model::factory('page');

$list = $pagesModel->query()
->params(['sort' => ['parent_id', 'order_no']])
->filters(['published' => true, 'in_site_map' => true])
->fields( [
'code',
'func_code',
'date_updated' => ' DATE_FORMAT(date_updated,"%Y-%m-%d")',
'date_created' => ' DATE_FORMAT(date_created,"%Y-%m-%d")'
])
->fetchAll();

$curDate = date('Y-m-d');

$request = Request::factory();
$xml = '';
foreach ($list as $k => $v)
{
$url = $request->url([$v['code']]);

if (!empty($v['func_code'])) {
$xml .= $this->createItemXML($url, $curDate, self::CHANGEFREQ_DAILY, 0.9);
continue;
}

if (strlen($v['date_updated'])) {
$xml .= $this->createItemXML($url, $v['date_updated'], self::CHANGEFREQ_WEEKLY, 0.8);
} else {
$xml .= $this->createItemXML($url, $v['date_created'], self::CHANGEFREQ_WEEKLY, 0.8);
}
}
return $xml;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
<?php
class Dvelum_Backend_Sitemap_Installer extends Externals_Installer
namespace Dvelum\Sitemap;

use Dvelum\Config\ConfigInterface;
use Dvelum\App\Session\User;
use Dvelum\Orm\Model;
use Dvelum\Orm\Object;

class Installer extends \Externals_Installer
{
/**
* Install
* @param Config_Abstract $applicationConfig
* @param Config_Abstract $moduleConfig
* @param ConfigInterface $applicationConfig
* @param ConfigInterface $moduleConfig
* @return boolean
*/
public function install(Config_Abstract $applicationConfig, Config_Abstract $moduleConfig)
public function install(ConfigInterface $applicationConfig, ConfigInterface $moduleConfig)
{
$userId = User::getInstance()->getId();

$pagesModel = Model::factory('Page');
$pageItem = $pagesModel->getList(false,['func_code' => 'dvelum_sitemap']);
$pageItemExists = $pagesModel->query()->filters(['func_code' => 'dvelum_sitemap'])->getCount();

if(empty($pageItem))
if(!$pageItemExists)
{
try{
$sitemapPage = new Db_Object('Page');
$sitemapPage->setValues(array(
$sitemapPage = Object::factory('Page');
$sitemapPage->setValues([
'code'=>'sitemap',
'is_fixed'=>1,
'html_title'=>'Sitemap XML',
Expand All @@ -42,15 +49,15 @@ public function install(Config_Abstract $applicationConfig, Config_Abstract $mod
'date_published'=>date('Y-m-d H:i:s'),
'in_site_map'=>false,
'default_blocks'=>true
));
]);

if(!$sitemapPage->saveVersion(true, false))
throw new Exception('Cannot create sitemap page');
throw new \Exception('Cannot create sitemap page');

if(!$sitemapPage->publish())
throw new Exception('Cannot publish sitemap page');
throw new \Exception('Cannot publish sitemap page');

}catch (Exception $e){
}catch (\Exception $e){
$this->errors[] = $e->getMessage();
return false;
}
Expand All @@ -59,21 +66,21 @@ public function install(Config_Abstract $applicationConfig, Config_Abstract $mod

/**
* Uninstall
* @param Config_Abstract $applicationConfig
* @param Config_Abstract $moduleConfig
* @param ConfigInterface $applicationConfig
* @param ConfigInterface $moduleConfig
* @return boolean
*/
public function uninstall(Config_Abstract $applicationConfig, Config_Abstract $moduleConfig)
public function uninstall(ConfigInterface $applicationConfig, ConfigInterface $moduleConfig)
{
$pagesModel = Model::factory('Page');
$pageItems = $pagesModel->getList(false,['func_code' => 'dvelum_sitemap']);
$pageItems = $pagesModel->query()->filters(['func_code' => 'dvelum_sitemap'])->fetchAll();

foreach($pageItems as $item)
{
try{
$page = Db_Object::factory('Page', $item['id']);
$page = Object::factory('Page', $item['id']);
$page->unpublish();
}catch (Exception $e){
}catch (\Exception $e){
$this->errors[] = $e->getMessage();
return false;
}
Expand Down
43 changes: 0 additions & 43 deletions classes/Dvelum/Sitemap/Pages.php

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"source": "https://github.com/dvelum/module-sitemap"
},
"require": {
"php":">=5.5",
"php":">=7.1",
"oomphinc/composer-installers-extender": "^1.1",
"dvelum/dvelum": ">=1.0.2"
"dvelum/dvelum": ">=2.0.0"
}
}
4 changes: 2 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
return [
'id' => 'dvelum_sitemap',
'id' => 'dvelum-module-sitemap',
'version' => '1.0.4',
'author' => 'Kirill Yegorov',
'name' => 'DVelum Sitemap',
Expand All @@ -10,5 +10,5 @@
'autoloader'=> [
'./classes'
],
'post-install'=>'Dvelum_Backend_Sitemap_Installer'
'post-install'=>'\\Dvelum\\Sitemap\\Installer'
];
2 changes: 1 addition & 1 deletion configs/modules_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
'dvelum_sitemap' =>
array (
'code' => 'dvelum_sitemap',
'class' =>'Dvelum_Frontend_Sitemap_Controller'
'class' =>'\\Dvelum\\App\\Frontend\\Sitemap\\Controller'
),
);
2 changes: 1 addition & 1 deletion configs/sitemap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
return[
'pages' => 'Dvelum_Sitemap_Pages'
'pages' => '\\Dvelum\\Sitemap\\Adapter\\Pages'
];
41 changes: 0 additions & 41 deletions locales/en/objects.php

This file was deleted.

0 comments on commit 1938f31

Please sign in to comment.