<?php
/**
* @package XenCentral Feedback System
* @author DNF Technology
* @copyright Drnoyan & Nalyan LDA, Portugal, EU
* @license http://dnf.technology/terms/
* @link http://customers.dnf.technology
* @version 2.0.0 Beta 10
* @revision 12
*/
namespace XenCentral\Feedback;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Create;
use XF\Db\Schema\Alter;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
public function installStep1(array $stepParams = [])
{
$sm = $this->schemaManager();
foreach ($this->getTables() AS $tableName => $closure)
{
$sm->createTable($tableName, $closure);
}
}
public function upgrade2000031Step1() {
$sm = $this->schemaManager();
$renameTables = [
'xc_trade_activity' => 'xf_xc_feedback_activity',
'xc_trade_comment' => 'xf_xc_feedback_comment',
'xc_trade_feedback' => 'xf_xc_feedback_feedback',
'xc_trade_notification_queue' => 'xf_xc_feedback_notification_queue',
'xc_trade_preference' => 'xf_xc_feedback_preference',
'xc_trade_user' => 'xf_xc_feedback_user'
];
foreach ($renameTables AS $from => $to)
{
$sm->renameTable($from, $to);
}
$sm->alterTable('xf_xc_feedback_preference', function(Alter $table)
{
$table->renameColumn('xc_trade_notify_email', 'xc_feedback_notify_email');
$table->renameColumn('xc_trade_notify_pm', 'xc_feedback_notify_pm');
$table->renameColumn('xc_trade_notify_notification', 'xc_feedback_notify_notification');
$table->renameColumn('xc_trade_is_invisible', 'xc_feedback_is_invisible');
});
$this->query("
UPDATE xf_route_filter
SET
prefix = 'feedback',
find_route = REPLACE(find_route, 'xcxt/', 'feedback/')
WHERE prefix = 'xcxt'
");
$this->app->repository('XF:RouteFilter')->rebuildRouteFilterCache();
}
public function upgrade2000037Step1() {
$sm = $this->schemaManager();
$sm->alterTable( 'xf_xc_feedback_feedback', function ( Alter $table ) {
$table->changeColumn( 'importid' )->type( 'bigint' )->nullable( false )->unsigned()->setDefault( 0 );
} );
$sm->alterTable( 'xf_xc_feedback_comment', function ( Alter $table ) {
$table->changeColumn( 'importid' )->type( 'bigint' )->nullable( false )->unsigned()->setDefault( 0 );
} );
$sm->alterTable( 'xf_xc_feedback_notification_queue', function ( Alter $table ) {
$table->changeColumn( 'importid' )->type( 'bigint' )->nullable( false )->unsigned()->setDefault( 0 );
} );
$sm->alterTable( 'xf_xc_feedback_feedback', function ( Alter $table ) {
$table->changeColumn( 'dealurl' )->type( 'varchar', '1000' )->nullable( false );
} );
}
public function uninstallStep1()
{
$sm = $this->schemaManager();
foreach (array_keys($this->getTables()) AS $tableName)
{
$sm->dropTable($tableName);
}
}
public function uninstallStep2()
{
$db = $this->db();
$db->delete('xf_route_filter', 'prefix = ?', 'feedback');
$this->app->repository('XF:RouteFilter')->rebuildRouteFilterCache();
}
protected function getTables()
{
$tables = [];
$tables['xf_xc_feedback_feedback'] = function (Create $table) {
$table->addColumn('fb_id', 'int')->autoIncrement()->nullable(false)->unsigned();
$table->addColumn('foruserid', 'int')->nullable(false)->unsigned();
$table->addColumn('fromuserid', 'int')->nullable(false)->unsigned();
$table->addColumn('amount', 'tinyint')->nullable(false)->unsigned(false);
$table->addColumn('type', 'enum')->values(['buy','sell','trade']);
$table->addColumn('review', 'varchar', 255)->nullable(false);
$table->addColumn('dealurl', 'varchar', 1000)->nullable(false);
$table->addColumn('threadid', 'int')->nullable(false)->unsigned();
$table->addColumn('dateline', 'int')->nullable(false)->unsigned();
$table->addColumn('ip_id', 'int')->nullable(false)->unsigned();
$table->addColumn('importid', 'bigint')->nullable(false)->unsigned()->setDefault(0);
$table->addColumn('has_reply', 'tinyint')->nullable(false)->unsigned()->setDefault(1);
$table->addPrimaryKey(['fb_id']);
$table->addKey('foruserid', 'foruserid');
$table->addKey('fromuserid', 'fromuserid');
$table->addKey('importid', 'importid');
$table->addKey('threadid', 'threadid');
$table->addKey(['amount', 'dateline'], 'amount');
};
$tables['xf_xc_feedback_comment'] = function (Create $table) {
$table->addColumn('comment_id', 'int')->autoIncrement()->nullable(false)->unsigned();
$table->addColumn('fb_id', 'int')->nullable(false)->unsigned();
$table->addColumn('user_id', 'int')->nullable(false)->unsigned();
$table->addColumn('message', 'mediumtext')->nullable(false);
$table->addColumn('dateline', 'int')->nullable(false)->unsigned();
$table->addColumn('ip_id', 'int')->nullable(false)->unsigned();
$table->addColumn('importid', 'bigint')->nullable(false)->unsigned()->setDefault(0);
$table->addPrimaryKey(['comment_id']);
$table->addKey('fb_id', 'fb_id');
$table->addKey('importid', 'importid');
};
$tables['xf_xc_feedback_user'] = function (Create $table) {
$table->addColumn('user_id', 'int')->nullable(false)->unsigned();
$table->addColumn('fb_total', 'int')->nullable(false)->unsigned(false);
$table->addColumn('fb_positivetotal', 'int')->nullable(false)->unsigned();
$table->addColumn('fb_positive', 'int')->nullable(false)->unsigned();
$table->addColumn('fb_negative', 'int')->nullable(false)->unsigned();
$table->addColumn('fb_neutral', 'int')->nullable(false)->unsigned();
$table->addColumn('fb_percent', 'float')->nullable(false)->unsigned();
$table->addColumn('fb_stats', 'text')->nullable(false);
$table->addPrimaryKey(['user_id']);
};
$tables['xf_xc_feedback_activity'] = function (Create $table) {
$table->addColumn('user_id', 'int')->nullable(false)->unsigned();
$table->addColumn('log_hash', 'varchar', 32)->nullable(false);
$table->addColumn('dateline', 'int')->nullable(false)->unsigned();
$table->addColumn('phrase', 'varchar', 100)->nullable(false);
$table->addColumn('args', 'text')->nullable(false);
$table->addColumn('link', 'text')->nullable();
$table->addColumn('state', 'char', 10)->nullable(false);
$table->addPrimaryKey(['log_hash']);
$table->addKey(['user_id','dateline'], 'user_id_dateline');
$table->addKey(['state','dateline'], 'state');
$table->addKey(['phrase','state','dateline'], 'phrase');
};
$tables['xf_xc_feedback_preference'] = function (Create $table) {
$table->addColumn('pr_user_id', 'int')->nullable(false)->unsigned();
$table->addColumn('xc_feedback_notify_email', 'varchar', 255)->nullable(false)->setDefault('');
$table->addColumn('xc_feedback_notify_pm', 'varchar', 255)->nullable(false)->setDefault('');
$table->addColumn('xc_feedback_notify_notification', 'varchar', 255)->nullable(false)->setDefault('');
$table->addColumn('xc_feedback_is_invisible', 'tinyint')->nullable(false)->unsigned()->setDefault(0);
$table->addPrimaryKey(['pr_user_id']);
};
$tables['xf_xc_feedback_notification_queue'] = function (Create $table) {
$table->addColumn('id', 'int')->autoIncrement()->nullable(false)->unsigned();
$table->addColumn('forUserId', 'int')->nullable(false)->unsigned()->setDefault(0);
$table->addColumn('date', 'int')->nullable(false)->unsigned()->setDefault(0);
$table->addColumn('handler', 'varchar', 255)->nullable(false)->setDefault('');
$table->addColumn('sent', 'tinyint')->nullable(false)->unsigned()->setDefault(0);
$table->addColumn('extraData', 'text')->nullable(false);
$table->addColumn('importid', 'bigint')->nullable(false)->unsigned()->setDefault(0);
$table->addPrimaryKey(['id']);
$table->addKey('sent');
};
return $tables;
}
}