use database namespace
This commit is contained in:
parent
2c6764c95c
commit
dae88e0407
@ -15,11 +15,13 @@ declare(strict_types=1);
|
|||||||
namespace Dotclear\Plugin\activityReport;
|
namespace Dotclear\Plugin\activityReport;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use cursor;
|
|
||||||
use dcBlog;
|
use dcBlog;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcRecord;
|
|
||||||
use dcUtils;
|
use dcUtils;
|
||||||
|
use Dotclear\Database\{
|
||||||
|
Cursor,
|
||||||
|
MetaRecord
|
||||||
|
};
|
||||||
use Dotclear\Helper\Network\Http;
|
use Dotclear\Helper\Network\Http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +272,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog(My::id(), 'message', $logs);
|
ActivityReport::instance()->addLog(My::id(), 'message', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function blogUpdate(cursor $cur, string $blog_id): void
|
public static function blogUpdate(Cursor $cur, string $blog_id): void
|
||||||
{
|
{
|
||||||
$logs = [(string) dcCore::app()->auth?->getInfo('user_cn')];
|
$logs = [(string) dcCore::app()->auth?->getInfo('user_cn')];
|
||||||
ActivityReport::instance()->addLog('blog', 'update', $logs);
|
ActivityReport::instance()->addLog('blog', 'update', $logs);
|
||||||
@ -285,7 +287,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('blog', 'p404', $logs);
|
ActivityReport::instance()->addLog('blog', 'p404', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function postCreate(cursor $cur, int $post_id): void
|
public static function postCreate(Cursor $cur, int $post_id): void
|
||||||
{
|
{
|
||||||
$type = $cur->getField('post_type') ?? 'post';
|
$type = $cur->getField('post_type') ?? 'post';
|
||||||
$post_url = dcCore::app()->blog?->getPostURL('', $cur->getField('post_dt'), $cur->getField('post_title'), $post_id);
|
$post_url = dcCore::app()->blog?->getPostURL('', $cur->getField('post_dt'), $cur->getField('post_title'), $post_id);
|
||||||
@ -297,7 +299,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('post', 'create', $logs);
|
ActivityReport::instance()->addLog('post', 'create', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function postUpdate(cursor $cur, int $post_id): void
|
public static function postUpdate(Cursor $cur, int $post_id): void
|
||||||
{
|
{
|
||||||
$type = $cur->getField('post_type') ?? 'post';
|
$type = $cur->getField('post_type') ?? 'post';
|
||||||
$post_url = dcCore::app()->blog?->getPostURL('', $cur->getField('post_dt'), $cur->getField('post_title'), $post_id);
|
$post_url = dcCore::app()->blog?->getPostURL('', $cur->getField('post_dt'), $cur->getField('post_title'), $post_id);
|
||||||
@ -334,7 +336,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('post', 'protection', $logs);
|
ActivityReport::instance()->addLog('post', 'protection', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function commentCreate(dcBlog $blog, cursor $cur): void
|
public static function commentCreate(dcBlog $blog, Cursor $cur): void
|
||||||
{
|
{
|
||||||
if ($cur->getField('comment_trackback')) {
|
if ($cur->getField('comment_trackback')) {
|
||||||
return;
|
return;
|
||||||
@ -355,7 +357,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('comment', 'create', $logs);
|
ActivityReport::instance()->addLog('comment', 'create', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function commentUpdate(dcBlog $blog, cursor $cur, dcRecord $old): void
|
public static function commentUpdate(dcBlog $blog, Cursor $cur, MetaRecord $old): void
|
||||||
{
|
{
|
||||||
$posts = dcCore::app()->blog?->getPosts(
|
$posts = dcCore::app()->blog?->getPosts(
|
||||||
['post_id' => $old->f('post_id'), 'limit' => 1]
|
['post_id' => $old->f('post_id'), 'limit' => 1]
|
||||||
@ -373,7 +375,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('comment', 'update', $logs);
|
ActivityReport::instance()->addLog('comment', 'update', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function trackbackCreate(dcBlog $blog, cursor $cur): void
|
public static function trackbackCreate(dcBlog $blog, Cursor $cur): void
|
||||||
{
|
{
|
||||||
if (!$cur->getField('comment_trackback')) {
|
if (!$cur->getField('comment_trackback')) {
|
||||||
return;
|
return;
|
||||||
@ -396,7 +398,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('comment', 'trackback', $logs);
|
ActivityReport::instance()->addLog('comment', 'trackback', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function categoryCreate(cursor $cur, int $cat_id): void
|
public static function categoryCreate(Cursor $cur, int $cat_id): void
|
||||||
{
|
{
|
||||||
$logs = [
|
$logs = [
|
||||||
(string) $cur->getField('cat_title'),
|
(string) $cur->getField('cat_title'),
|
||||||
@ -406,7 +408,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('category', 'create', $logs);
|
ActivityReport::instance()->addLog('category', 'create', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function categoryUpdate(cursor $cur, int $cat_id): void
|
public static function categoryUpdate(Cursor $cur, int $cat_id): void
|
||||||
{
|
{
|
||||||
$logs = [
|
$logs = [
|
||||||
(string) $cur->getField('cat_title'),
|
(string) $cur->getField('cat_title'),
|
||||||
@ -416,7 +418,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('category', 'update', $logs);
|
ActivityReport::instance()->addLog('category', 'update', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function userCreate(cursor $cur, string $user_id): void
|
public static function userCreate(Cursor $cur, string $user_id): void
|
||||||
{
|
{
|
||||||
$user_cn = dcUtils::getUserCN(
|
$user_cn = dcUtils::getUserCN(
|
||||||
$cur->getField('user_id'),
|
$cur->getField('user_id'),
|
||||||
@ -431,7 +433,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('user', 'create', $logs);
|
ActivityReport::instance()->addLog('user', 'create', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function userUpdate(cursor $cur, string $user_id): void
|
public static function userUpdate(Cursor $cur, string $user_id): void
|
||||||
{
|
{
|
||||||
$user_cn = dcUtils::getUserCN(
|
$user_cn = dcUtils::getUserCN(
|
||||||
$cur->getField('user_id'),
|
$cur->getField('user_id'),
|
||||||
@ -446,7 +448,7 @@ class ActivityBehaviors
|
|||||||
ActivityReport::instance()->addLog('user', 'update', $logs);
|
ActivityReport::instance()->addLog('user', 'update', $logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function userPreference(cursor $cur, string $user_id): void
|
public static function userPreference(Cursor $cur, string $user_id): void
|
||||||
{
|
{
|
||||||
$user = dcCore::app()->getUser($user_id);
|
$user = dcCore::app()->getUser($user_id);
|
||||||
if ($user->isEmpty()) {
|
if ($user->isEmpty()) {
|
||||||
|
@ -18,7 +18,7 @@ use ArrayObject;
|
|||||||
use dcAuth;
|
use dcAuth;
|
||||||
use dcBlog;
|
use dcBlog;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcRecord;
|
use Dotclear\Database\MetaRecord;
|
||||||
use Dotclear\Database\Statement\{
|
use Dotclear\Database\Statement\{
|
||||||
DeleteStatement,
|
DeleteStatement,
|
||||||
JoinStatement,
|
JoinStatement,
|
||||||
@ -61,6 +61,7 @@ class ActivityReport
|
|||||||
/** @var ActivityReport $instance ActivityReport instance */
|
/** @var ActivityReport $instance ActivityReport instance */
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
|
/** @var null|resource $lock File lock for update */
|
||||||
private $lock = null;
|
private $lock = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,9 +101,9 @@ class ActivityReport
|
|||||||
* @param bool $count_only Count only
|
* @param bool $count_only Count only
|
||||||
* @param null|SelectStatement $ext_sql The sql select statement
|
* @param null|SelectStatement $ext_sql The sql select statement
|
||||||
*
|
*
|
||||||
* @return null|dcRecord The logs record
|
* @return null|MetaRecord The logs record
|
||||||
*/
|
*/
|
||||||
public function getLogs(ArrayObject $params = null, bool $count_only = false, ?SelectStatement $ext_sql = null): ?dcRecord
|
public function getLogs(ArrayObject $params = null, bool $count_only = false, ?SelectStatement $ext_sql = null): ?MetaRecord
|
||||||
{
|
{
|
||||||
if (is_null($params)) {
|
if (is_null($params)) {
|
||||||
$params = new ArrayObject();
|
$params = new ArrayObject();
|
||||||
@ -271,11 +272,11 @@ class ActivityReport
|
|||||||
/**
|
/**
|
||||||
* Parse logs using a format.
|
* Parse logs using a format.
|
||||||
*
|
*
|
||||||
* @param dcRecord $rs The logs record
|
* @param MetaRecord $rs The logs record
|
||||||
*
|
*
|
||||||
* @return string The parsed logs
|
* @return string The parsed logs
|
||||||
*/
|
*/
|
||||||
private function parseLogs(dcRecord $rs): string
|
private function parseLogs(MetaRecord $rs): string
|
||||||
{
|
{
|
||||||
$from = time();
|
$from = time();
|
||||||
$to = 0;
|
$to = 0;
|
||||||
|
@ -14,9 +14,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\activityReport;
|
namespace Dotclear\Plugin\activityReport;
|
||||||
|
|
||||||
use dbStruct;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
|
use Dotclear\Database\Structure;
|
||||||
use Dotclear\Database\Statement\{
|
use Dotclear\Database\Statement\{
|
||||||
DropStatement,
|
DropStatement,
|
||||||
TruncateStatement
|
TruncateStatement
|
||||||
@ -46,16 +46,16 @@ class Install extends dcNsProcess
|
|||||||
try {
|
try {
|
||||||
self::beforeGrowUp();
|
self::beforeGrowUp();
|
||||||
|
|
||||||
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
|
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
||||||
$s->{My::ACTIVITY_TABLE_NAME}
|
$s->__get(My::ACTIVITY_TABLE_NAME)
|
||||||
->activity_id('bigint', 0, false)
|
->field('activity_id', 'bigint', 0, false)
|
||||||
->activity_type('varchar', 32, false, "'" . My::id() . "'")
|
->field('activity_type', 'varchar', 32, false, "'" . My::id() . "'")
|
||||||
->blog_id('varchar', 32, true)
|
->field('blog_id', 'varchar', 32, true)
|
||||||
->activity_group('varchar', 32, false)
|
->field('activity_group', 'varchar', 32, false)
|
||||||
->activity_action('varchar', 32, false)
|
->field('activity_action', 'varchar', 32, false)
|
||||||
->activity_logs('text', 0, false)
|
->field('activity_logs', 'text', 0, false)
|
||||||
->activity_dt('timestamp', 0, false, 'now()')
|
->field('activity_dt', 'timestamp', 0, false, 'now()')
|
||||||
->activity_status('smallint', 0, false, 0)
|
->field('activity_status', 'smallint', 0, false, 0)
|
||||||
|
|
||||||
->primary('pk_activity', 'activity_id')
|
->primary('pk_activity', 'activity_id')
|
||||||
->index('idx_activity_type', 'btree', 'activity_type')
|
->index('idx_activity_type', 'btree', 'activity_type')
|
||||||
@ -63,7 +63,7 @@ class Install extends dcNsProcess
|
|||||||
->index('idx_activity_action', 'btree', 'activity_group', 'activity_action')
|
->index('idx_activity_action', 'btree', 'activity_group', 'activity_action')
|
||||||
->index('idx_activity_status', 'btree', 'activity_status');
|
->index('idx_activity_status', 'btree', 'activity_status');
|
||||||
|
|
||||||
(new dbStruct(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
|
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -82,7 +82,7 @@ class Install extends dcNsProcess
|
|||||||
|
|
||||||
// sorry not sorry we restart from scratch
|
// sorry not sorry we restart from scratch
|
||||||
if ($current && version_compare($current, '3.0', '<')) {
|
if ($current && version_compare($current, '3.0', '<')) {
|
||||||
$struct = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
|
$struct = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
||||||
|
|
||||||
if ($struct->tableExists('activity')) {
|
if ($struct->tableExists('activity')) {
|
||||||
(new TruncateStatement())->from(dcCore::app()->prefix . 'activity')->truncate();
|
(new TruncateStatement())->from(dcCore::app()->prefix . 'activity')->truncate();
|
||||||
|
Loading…
Reference in New Issue
Block a user