Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #38

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
13 changes: 4 additions & 9 deletions assets/tracker.dashboard.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
div#dashboard .tracker_log table {
width: 100%;
.tracker_activity .panel-inner {
padding: 0;
}

div#dashboard .tracker_log table th,
div#dashboard .tracker_log table td {
padding: 1px 10px 1px 0;
.tracker_activity table {
border: none;
}

div#dashboard .tracker_log table th {
text-align: left;
}
55 changes: 36 additions & 19 deletions content/content.index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public function view()
// Add a button to clear all activity, if developer
if (Tracker::Author()->isDeveloper()) {
$clearform = Widget::Form(Symphony::Engine()->getCurrentPageURL(), 'post');
$button = new XMLElement('button', __('Clear All'));
Widget::registerSVGIcon(
'close',
'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="19.9px" height="19.9px" viewBox="0 0 19.9 19.9"><path fill="currentColor" d="M1,19.9c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4L18.2,0.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4L1.7,19.6C1.5,19.8,1.3,19.9,1,19.9z"/><path fill="currentColor" d="M18.9,19.9c-0.3,0-0.5-0.1-0.7-0.3L0.3,1.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l17.9,17.9c0.4,0.4,0.4,1,0,1.4C19.4,19.8,19.2,19.9,18.9,19.9z"/></svg>'
);
$button = new XMLElement(
'button',
Widget::SVGIcon('close') . '<span><span>' . __('Clear All') . '</span></span>'
);
$button->setAttributeArray(array('name' => 'action[clear-all]', 'class' => 'button confirm delete', 'title' => __('Clear all activity'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to clear all activity?')));
$clearform->appendChild($button);

Expand All @@ -42,13 +49,9 @@ public function view()
$filters = array();

if (isset($_REQUEST['filter'])) {

list($column, $value) = explode(':', $_REQUEST['filter'], 2);
$values = explode(',', $value);
$filters[$column] = array();

foreach ($values as $value) {
$filters[$column][] = rawurldecode($value);
foreach (explode('-', $_REQUEST['filter']) as $key => $value) {
$filter = explode(':', $value);
$filters[$filter[0]] = explode(',', rawurldecode($filter[1]));
}
}

Expand Down Expand Up @@ -112,10 +115,12 @@ public function view()

// Assemble the columns
$col_date = Widget::TableData($date);
$col_date->setAttribute('data-title', __('Date'));
$col_time = Widget::TableData($time);
$col_time->setAttribute('data-title', __('Time'));
$col_desc = Widget::TableData($description, $description_class);

$col_desc->appendChild(Widget::Input("items[{$activity['id']}]", null, 'checkbox'));
$col_desc->setAttribute('data-title', __('Activity'));

// Insert the row
$tbody[] = Widget::TableRow(array($col_desc, $col_date, $col_time), $row_class, 'activity-' . $activity['id']);
Expand Down Expand Up @@ -145,13 +150,17 @@ public function view()

// Append pagination
$filter_sql = Tracker::buildFilterSQL($filters);
$sql = '
SELECT count(id) as `count`
FROM `tbl_tracker_activity`' .
$filter_sql
;
$per_page = Symphony::Configuration()->get('pagination_maximum_rows', 'symphony');
$total_entries = Symphony::Database()->fetchVar('count', 0, $sql);
$q = Symphony::Database()
->select(['count(id)' => 'count'])
->from('tbl_tracker_activity');
foreach ($filter_sql as $key => $value) {
$q->where([$key => $value]);
}
$total_entries = $q
->execute()
->variable('count');

$remaining_entries = max(0, $total_entries - ($start + $per_page));
$total_pages = max(1, ceil($total_entries * (1 / $per_page)));
$remaining_pages = max(0, $total_pages - $current_page);
Expand Down Expand Up @@ -204,16 +213,24 @@ public function __actionIndex()
$checked = @array_keys($_POST['items']);

if (@array_key_exists('clear-all', $_POST['action'])) {
$sql = 'TRUNCATE `tbl_tracker_activity`;';
Symphony::Database()->query($sql);
// $sql = 'TRUNCATE `tbl_tracker_activity`;';
// Symphony::Database()->query($sql);
Symphony::Database()
->truncate('tbl_tracker_activity')
->execute()
->success();

redirect(Administration::instance()->getCurrentPageURL());
} elseif (is_array($checked) && !empty($checked)) {

switch ($_POST['with-selected']) {

case 'delete':

Symphony::Database()->delete('tbl_tracker_activity', ' `id` IN("' . implode('","',$checked) . '")');
Symphony::Database()
->delete('tbl_tracker_activity')
->where(['id' => ['in' => $checked]])
->execute()
->success();

redirect(Administration::instance()->getCurrentPageURL());
break;
Expand Down
2 changes: 1 addition & 1 deletion data-sources/data.tracker_activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function execute(array &$param_pool = null)
);

// Build the <activity> element
$item = new XMLElement('activity', NULL, array(
$item = new XMLElement('activity', null, array(
'type' => $activity['action_type'],
'entry-id' => $activity['item_id']
));
Expand Down
80 changes: 54 additions & 26 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,33 @@ public function getSubscribedDelegates()

public function install()
{
Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_tracker_activity` (
`id` int(11) unsigned NOT NULL auto_increment,
`item_type` varchar(255),
`item_id` varchar(75),
`action_type` varchar(255),
`user_id` int(11),
`timestamp` timestamp,
`fallback_username` varchar(2048),
`fallback_description` varchar(2048),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");

return true;
return Symphony::Database()
->create('tbl_tracker_activity')
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'item_type' => 'varchar(255)',
'item_id' => [
'type' => 'varchar(75)',
'null' => true,
],
'action_type' => 'varchar(255)',
'user_id' => [
'type' => 'int(11)',
'null' => true,
],
'timestamp' => 'timestamp',
'fallback_username' => 'varchar(2048)',
'fallback_description' => 'varchar(2048)',
])
->keys([
'id' => 'primary',
])
->execute()
->success();
}

public function update($previousVersion = null)
Expand All @@ -287,21 +300,27 @@ public function update($previousVersion = null)

// less than 1.7.0
if ($ret && version_compare($previousVersion, '1.7.0', '<')) {
$ret = Symphony::Database()->query("
ALTER TABLE `tbl_tracker_activity`
MODIFY `fallback_username` varchar(2048),
MODIFY `fallback_description` varchar(2048);
");
$ret = Symphony::Database()
->alter('tbl_tracker_activity')
->modify([
'fallback_username' => 'varchar(2048)',
'fallback_description' => 'varchar(2048)',
])
->execute()
->success();
}

return $ret;
}

public function uninstall()
{
Symphony::Database()->query(
"DROP TABLE IF EXISTS `tbl_tracker_activity`;"
);
Symphony::Database()
->drop('tbl_tracker_activity')
->ifExists()
->execute()
->success();

Symphony::Configuration()->remove('tracker');

return Symphony::Configuration()->write();
Expand Down Expand Up @@ -806,7 +825,10 @@ public function appendPreferences($context)

$sm = new SectionManager(Administration::instance());

$sections = $sm->fetch();
$sections = $sm
->select()
->execute()
->rows();
$excluded_sections = explode(',', Symphony::Configuration()->get('excluded-sections', 'tracker'));

if (!empty($sections) && is_array($sections)) {
Expand Down Expand Up @@ -834,7 +856,10 @@ public function appendPreferences($context)
$options = array();

$am = new AuthorManager(Administration::instance());
$authors = $am->fetch();
$authors = $am
->select()
->execute()
->rows();
$excluded_authors = explode(',',Symphony::Configuration()->get('excluded-users', 'tracker'));

if (!empty($authors) && is_array($authors)) {
Expand Down Expand Up @@ -944,7 +969,7 @@ public function renderPanel($context)
// Check to see we are being called in the right context
// Dashboard also has `contentExtensionDashboardPanel_Config` which extends `AjaxPage`
if (method_exists($page, 'addStylesheetToHead')) {
$page->addStylesheetToHead(URL . '/extensions/tracker/assets/dashboard.css', 'screen', 151);
$page->addStylesheetToHead(URL . '/extensions/tracker/assets/tracker.dashboard.css', 'screen', 151);
}

$logs = Tracker::fetchActivities($filters, (int) $config['limit'], 0);
Expand Down Expand Up @@ -989,12 +1014,15 @@ public function renderPanel($context)

// Assemble the columns
$col_date = Widget::TableData($date);
$col_date->setAttribute('data-title', __('Activity'));
$col_time = Widget::TableData($time);
$col_time->setAttribute('data-title', __('Date'));
$col_desc = Widget::TableData($description);
$col_desc->setAttribute('data-title', __('Time'));

// Insert the row
if (!is_null($description)) {
$tbody[] = Widget::TableRow(array($col_desc, $col_date, $col_time), ($bOdd ? 'odd' : null));
$tbody[] = Widget::TableRow(array($col_desc, $col_date, $col_time));

$bOdd = !$bOdd;
}
Expand Down
7 changes: 6 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="tracker" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Tracker</name>
<name>Tracker Activity</name>
<description>Track user and system activity</description>
<repo type="github">https://github.com/symphonists/tracker</repo>
<url type="issues">https://github.com/symphonists/tracker/issues</url>
Expand All @@ -18,6 +18,11 @@
</author>
</authors>
<releases>
<release version="3.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
- Code refactoring for Database and EQFA
- Replace deprecated method fetch() by select()
</release>
<release version="2.1.2" date="2018-07-24" min="2.6.0" max="2.x.x">
- Set Author Id to 0 if no author is set (#42)
</release>
Expand Down
Loading