Skip to content

Commit

Permalink
Merge pull request #2 from joomlatools/feature/1-sync
Browse files Browse the repository at this point in the history
Feature/1 sync
  • Loading branch information
amazeika authored Oct 14, 2016
2 parents 08376b6 + cb74580 commit 2dbc5a2
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 91 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ The following K2 actions are currently logged:
* Delete
* Publish
* Unpublish

* Trash

### Categories

* Add
* Edit
* Delete
* Publish
* Unpublish

## Limitations

Trash actions on both categories and items are not supported since no events are internally triggered by K2 upon those actions.
* Trash
4 changes: 2 additions & 2 deletions activity/category.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package LOGman
* @copyright Copyright (C) 2011 - 2015 Timble CVBA. (http://www.timble.net)
* @copyright Copyright (C) 2011 - 2016 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
Expand All @@ -27,7 +27,7 @@ protected function _objectConfig(KObjectConfig $config)
{
$config->append(array(
'subtype' => array('object' => true, 'objectName' => 'K2'),
'url' => 'option=com_k2&view=category&cid=' . $this->row
'url' => array('admin' => 'option=com_k2&view=category&cid=' . $this->row)
));

parent::_objectConfig($config);
Expand Down
4 changes: 2 additions & 2 deletions activity/item.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package LOGman
* @copyright Copyright (C) 2011 - 2015 Timble CVBA. (http://www.timble.net)
* @copyright Copyright (C) 2011 - 2016 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
Expand All @@ -27,7 +27,7 @@ protected function _objectConfig(KObjectConfig $config)
{
$config->append(array(
'subtype' => array('object' => true, 'objectName' => 'K2'),
'url' => 'option=com_k2&view=item&cid=' . $this->row
'url' => array('admin' => 'option=com_k2&view=item&cid=' . $this->row)
));

parent::_objectConfig($config);
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joomlatools/plg_logman_k2",
"type": "joomla-extension",
"name": "joomlatools/logman-k2",
"type": "joomlatools-composer",
"license": "GPLv3",
"description": "Handles logging of K2 component events",
"keywords": [
Expand All @@ -19,6 +19,6 @@
}
],
"require": {
"nooku/installer": "*"
"joomlatools/composer": "*"
}
}
22 changes: 4 additions & 18 deletions install.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package LOGman
* @copyright Copyright (C) 2011 - 2014 Timble CVBA. (http://www.timble.net)
* @copyright Copyright (C) 2011 - 2016 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
Expand All @@ -24,24 +24,10 @@ public function preflight($type, $installer)
$return = true;
$errors = array();

if (!class_exists('Koowa') || !class_exists('ComExtmanControllerExtension'))
if (version_compare($this->getLogmanVersion(), '3.0.0', '<'))
{
if (file_exists(JPATH_ADMINISTRATOR.'/components/com_extman/extman.php') && !JPluginHelper::isEnabled('system', 'koowa')) {
$errors[] = sprintf(JText::_('This component requires System - Nooku Framework plugin to be installed and enabled. Please go to <a href=%s>Plugin Manager</a>, enable <strong>System - Nooku Framework</strong> and try again'), JRoute::_('index.php?option=com_plugins&view=plugins&filter_folder=system'));
}
else $errors[] = JText::_('This component requires EXTman to be installed on your site. Please download this component from <a href=http://joomlatools.com target=_blank>joomlatools.com</a> and install it');

$return = false;
}

// Check LOGman version.
if ($return === true)
{
if (version_compare($this->getLogmanVersion(), '2.0.2', '<'))
{
$errors[] = JText::_('This component requires a newer LOGman version. Please download the latest version from <a href=http://joomlatools.com target=_blank>joomlatools.com</a> and upgrade.');
$return = false;
}
$errors[] = JText::_('This plugin requires a newer LOGman version. Please download the latest version from <a href=http://joomlatools.com target=_blank>joomlatools.com</a> and upgrade.');
$return = false;
}

if ($return == false && $errors)
Expand Down
41 changes: 28 additions & 13 deletions k2.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package LOGman
* @copyright Copyright (C) 2011 - 2015 Timble CVBA. (http://www.timble.net)
* @copyright Copyright (C) 2011 - 2016 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
Expand All @@ -14,15 +14,8 @@
*/
class PlgLogmanK2 extends ComLogmanPluginJoomla
{
protected function _initialize(KObjectConfig $config)
{
$config->append(array('resources' => array('item', 'category')));
parent::_initialize($config);
}

protected function _getItemObjectData($data, $event)
{

return array('id' => $data->id, 'name' => $data->title);
}

Expand All @@ -33,22 +26,20 @@ protected function _getCategoryObjectData($data, $event)

public function onFinderAfterSave($context, $row, $isNew)
{
// Item model triggers both content and finder after save events. Only one should go through.
// Item controller triggers both content and finder after save events. Only one should go through.
if ($context != 'com_k2.item') {
$this->onContentAfterSave($context, $row, $isNew); // Forward event to the content event handler.
}
}

public function onFinderAfterDelete($context, $row)
{
// Forward event to the content event handler.
$this->onContentAfterDelete($context, $row);
$this->onContentAfterDelete($context, $row); // Forward event to the content event handler.
}

public function onFinderChangeState($context, $cid, $state)
{
// Forward event to the content event handler.
$this->onContentChangeState($context, $cid, $state);
$this->onContentChangeState($context, $cid, $state); // Forward event to the content event handler.
}

protected function _getItems($ids, KObjectConfig $config)
Expand All @@ -58,4 +49,28 @@ protected function _getItems($ids, KObjectConfig $config)

return parent::_getItems($ids, $config);
}

public function onContentChangeState($context, $pks, $state)
{
if (in_array($context, $this->_contexts))
{
$parts = explode('.', $context);

$table = sprintf('k2_%s', KStringInflector::pluralize($parts[1]));

$adapter = $this->getObject('lib:database.adapter.mysqli');

$query = $this->getObject('lib:database.query.select')
->table($table)
->columns('trash')
->where('id IN :id')
->bind(array('id' => $pks));

if ($adapter->select($query, KDatabase::FETCH_FIELD) == 1) {
$state = -2; // Set state as trash
}
}

parent::onContentChangeState($context, $pks, $state);
}
}
30 changes: 26 additions & 4 deletions k2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,46 @@
<identifier>plg:logman.k2</identifier>
<name>plg_logman_k2</name>
<author>Joomlatools</author>
<creationDate>January 2015</creationDate>
<copyright>Copyright (C) 2011 - 2015 Timble CVBA (http://www.timble.net)</copyright>
<creationDate>October 2016</creationDate>
<copyright>Copyright (C) 2011 - 2016 Timble CVBA (http://www.timble.net)</copyright>
<license>GNU GPLv3 - http://www.gnu.org/licenses/gpl.html</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomlatools.com</authorUrl>
<version>2.0.0</version>
<version>3.0.0</version>
<description>PLG_LOGMAN_K2_DESC</description>

<scriptfile>install.php</scriptfile>

<files>
<filename plugin="k2">k2.php</filename>
<filename>version.php</filename>
<folder>activity</folder>
<folder>language</folder>
</files>

<config>
<fields name="params" />
</config>

<resources>
<resource name="item">
<actions>
<action>add</action>
<action>edit</action>
<action>delete</action>
<action>publish</action>
<action>unpublish</action>
<action>trash</action>
</actions>
</resource>
<resource name="category">
<actions>
<action>add</action>
<action>edit</action>
<action>delete</action>
<action>publish</action>
<action>unpublish</action>
<action>trash</action>
</actions>
</resource>
</resources>
</extension>
2 changes: 1 addition & 1 deletion language/en-GB/en-GB.plg_logman_k2.sys.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; Copyright © 2015 Timble CVBA. (http://www.timble.net)
; Copyright © 2016 Timble CVBA. (http://www.timble.net)
; GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
; Note : All ini files need to be saved as UTF-8

Expand Down
43 changes: 0 additions & 43 deletions version.php

This file was deleted.

0 comments on commit 2dbc5a2

Please sign in to comment.