Skip to content

Commit aa1d44b

Browse files
committed
create models and system configuration
1 parent 9ef30c8 commit aa1d44b

File tree

7 files changed

+309
-65
lines changed

7 files changed

+309
-65
lines changed

CmsSync/Model/Cms.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Created by Calin Diacon.
4+
* User: cdiacon
5+
* Date: 17/02/2013
6+
* Time: 14:08
7+
*
8+
*/
9+
class CalinDiacon_CmsSync_Model_Cms
10+
{
11+
protected $blockId = false;
12+
protected $isMaster = false;
13+
protected $isEnabled = false;
14+
/**
15+
* Sync the static block
16+
* @param $blockId
17+
*/
18+
public function syncStaticBlock($blockId)
19+
{
20+
21+
/**
22+
* verify the source and get nodes info
23+
**/
24+
$validNodes = $this->getEnabledNodes();
25+
26+
27+
28+
if($blockId){
29+
30+
$model = Mage::getModel('cms/block');
31+
32+
if(! $id = $model->load($blockId)){
33+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists!'));
34+
$this->_redirect('*/*');
35+
return;
36+
}
37+
38+
$identifier = $model->getIdentifier();
39+
$title = $model->getTitle();
40+
$content = $model->getContent();
41+
42+
$node1 = Mage::getStoreConfig('cmssync/general/urlone');
43+
$username = Mage::getStoreConfig('cmssync/general/usernameone');
44+
$passwordone = Mage::getStoreConfig('cmssync/general/passwordone');
45+
46+
47+
48+
$node1 = "http://calin.wineglassworld.dev/index.php/api/soap/?wsdl=1";
49+
50+
$options["connection_timeout"] = 255;
51+
$options["location"] = $node1;
52+
$options['trace'] = 1;
53+
54+
55+
56+
$proxy = new Zend_Soap_Client($node1);
57+
$sessionId = $proxy->login('admin', 'admin123');
58+
$email = 'cdiacon@gmail.com';
59+
$store = 0;
60+
61+
//$result = $proxy->catalogCategoryTree($sessionId);
62+
63+
64+
65+
//$proxy = new SoapClient($node1);
66+
//$sessionId = $proxy->login($username, $passwordone);
67+
68+
//$data = $proxy->call($session, 'catalog.product_info', array(1));
69+
//$data = $proxy->catalogCategoryTree($sessionId);
70+
$data = $proxy->call($sessionId , 'cms_api.info', 'THIS TEXT IS AWSOME!!!');//, array(1));// array($email, $store));
71+
//$data= $proxy->call($sessionId, 'customer.list', array(array()));
72+
73+
74+
//$data = $proxy->call($sessionId, 'config.api/get', array());
75+
76+
77+
78+
79+
var_dump($data);
80+
81+
die;
82+
83+
84+
}
85+
86+
}
87+
88+
/**
89+
*
90+
* Get defined nodes to sync
91+
* @return CalinDiacon_CmsSync_Model_NodeMapper
92+
*/
93+
public function getEnabledNodes()
94+
{
95+
$this->isEnabled = (Mage::getStoreConfig('cmssync/general/enabled'))? Mage::getStoreConfig('cmssync/general/enabled') : false;
96+
$this->isMaster = (Mage::getStoreConfig('cmssync/general/source'))? Mage::getStoreConfig('cmssync/general/source') : false;
97+
$nodeMapper = new CalinDiacon_CmsSync_Model_NodeMapper();
98+
99+
if ($this->isEnabled && $this->isMaster){
100+
101+
//@todo parse xml and get number of nodes
102+
for($i = 1; $i <= 3;$i++){
103+
104+
$node = new CalinDiacon_CmsSync_Model_Node();
105+
$url = Mage::getStoreConfig('cmssync/general/url_' . $i);
106+
$username = Mage::getStoreConfig('cmssync/general/username_' . $i);
107+
$password = Mage::getStoreConfig('cmssync/general/password_' . $i);
108+
$onemore = Mage::getStoreConfig('cmssync/general/onemore_'. $i);
109+
110+
$node->setUrl($url);
111+
$node->setUsername($username);
112+
$node->setPassword($password);
113+
114+
if ($node->isValid){
115+
$nodeMapper->nodes[] = $node;
116+
}
117+
if (!$onemore)
118+
break;
119+
}
120+
Mage::log('number of nodes : ' . $i);
121+
122+
}else{
123+
124+
Mage::throwException('The Source must be master and enabled!');
125+
}
126+
return $nodeMapper;
127+
}
128+
129+
130+
}

CmsSync/Model/Node.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Created by Calin Diacon.
4+
* User: cdiacon
5+
* Date: 17/02/2013
6+
* Time: 14:34
7+
*
8+
*/
9+
class CalinDiacon_CmsSync_Model_Node
10+
{
11+
protected $_url;
12+
protected $_username;
13+
protected $_password;
14+
public $lastone = false;
15+
public $isValid = true;
16+
17+
public function setUrl($url)
18+
{
19+
Mage::log('setting url ...' . $url);
20+
$result = Zend_Uri::check($url);
21+
Mage::log('url validation result : ' . $result);
22+
if ($result){
23+
$this->_url = $url;
24+
}else{
25+
$this->isValid = false;
26+
}
27+
return $this;
28+
29+
}
30+
31+
public function setUsername($username)
32+
{
33+
$this->_username = $username;
34+
return $this;
35+
}
36+
37+
public function setPassword($password)
38+
{
39+
$this->_password = $password;
40+
return $this;
41+
}
42+
43+
public function getUrl()
44+
{
45+
return $this->_url;
46+
}
47+
48+
public function getUsername()
49+
{
50+
return $this->_username;
51+
}
52+
53+
public function getPassword()
54+
{
55+
return $this->_password;
56+
}
57+
58+
59+
}

CmsSync/Model/NodeMapper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Created by Calin Diacon.
4+
* User: cdiacon
5+
* Date: 17/02/2013
6+
* Time: 14:34
7+
*
8+
*/
9+
class CalinDiacon_CmsSync_Model_NodeMapper
10+
{
11+
public $nodes = array();
12+
}

CmsSync/Model/Objectmodel/Api.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ public function info($args)
1717
{
1818
return '1 from the custom option info action from api ' . $args;
1919
}
20+
public function isEnabled()
21+
{
22+
$enabled = Mage::getStoreConfig('cmssync/general/enabled');
23+
return $enabled;
24+
}
25+
public function getSource()
26+
{
27+
return Mage::getStoreConfig('cmssync/general/source');
28+
}
29+
2030

2131
}

CmsSync/controllers/Adminhtml/Cms/BlockController.php

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,10 @@ public function syncAction()
2020

2121
protected function syncByBlockId($blockId = false)
2222
{
23-
if($blockId){
2423

25-
$model = Mage::getModel('cms/block');
24+
$cmsModel = new CalinDiacon_CmsSync_Model_Cms();
25+
$cmsModel->syncStaticBlock($blockId);
2626

27-
if(! $id = $model->load($blockId)){
28-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists!'));
29-
$this->_redirect('*/*');
30-
return;
31-
}
32-
33-
$identifier = $model->getIdentifier();
34-
$title = $model->getTitle();
35-
$content = $model->getContent();
36-
37-
$node1 = Mage::getStoreConfig('cmssync/general/urlone');
38-
$username = Mage::getStoreConfig('cmssync/general/usernameone');
39-
$passwordone = Mage::getStoreConfig('cmssync/general/passwordone');
40-
41-
42-
43-
$node1 = "http://calin.wineglassworld.dev/index.php/api/soap/?wsdl=1";
44-
45-
$options["connection_timeout"] = 255;
46-
$options["location"] = $node1;
47-
$options['trace'] = 1;
48-
49-
50-
51-
$proxy = new Zend_Soap_Client($node1);
52-
$sessionId = $proxy->login('admin', 'admin123');
53-
$email = 'cdiacon@gmail.com';
54-
$store = 0;
55-
56-
//$result = $proxy->catalogCategoryTree($sessionId);
57-
58-
59-
60-
//$proxy = new SoapClient($node1);
61-
//$sessionId = $proxy->login($username, $passwordone);
62-
63-
//$data = $proxy->call($session, 'catalog.product_info', array(1));
64-
//$data = $proxy->catalogCategoryTree($sessionId);
65-
$data = $proxy->call($sessionId , 'cms_api.info', 'THIS TEXT IS AWSOME!!!');//, array(1));// array($email, $store));
66-
//$data= $proxy->call($sessionId, 'customer.list', array(array()));
67-
68-
69-
//$data = $proxy->call($sessionId, 'config.api/get', array());
70-
71-
72-
73-
74-
var_dump($data);
75-
76-
die;
77-
78-
79-
}
8027

8128

8229

CmsSync/etc/api.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<title>Extended Customers API</title>
88
<acl>api</acl>
99
<methods>
10+
<is_enabled translate="title" module="calindiacon_cmssync">
11+
<title>Get Configuration status</title>
12+
<method>isEnabled</method>
13+
<acl>api/extended</acl>
14+
</is_enabled>
15+
<get_source translate="title" module="calindiacon_cmssync">
16+
<title>Get the source type</title>
17+
<method>getSource</method>
18+
</get_source>
1019
<info translate="title" module="calindiacon_cmssync">
1120
<title>Retrieve cutomers data with addresses</title>
1221
<method>info</method>

0 commit comments

Comments
 (0)