Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/views/tag_subscription/_user_listing.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php $has_subscriptions = !empty($user->tag_subscriptions) && $user->tag_subscriptions->size() > 0; ?>
<?php
$listingUser = $this->user ?? ($user ?? null);
$subscriptions = $listingUser ? $listingUser->tag_subscriptions : null;
$has_subscriptions = $subscriptions && $subscriptions->size() > 0;
?>

<?php if (!$has_subscriptions) : ?>
<?= $this->t('sub_none') ?>
<?php else : ?>
<?= $this->tag_subscription_listing($user) ?>
<?= $this->tag_subscription_listing($listingUser) ?>
<?php endif ?>

<?php if (current_user()->id == $user->id) : ?>
<?php if ($listingUser && current_user()->id == $listingUser->id) : ?>
(<?= $this->linkTo($this->t('sub_edit'), 'tag_subscription#index') ?>)
<?php endif ?>
47 changes: 47 additions & 0 deletions db/migrate/20260218221000_ensure_user_logs_table_exists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
class EnsureUserLogsTableExists extends Rails\ActiveRecord\Migration\Base
{
public function up()
{
if (!$this->tableExists('user_logs')) {
$this->execute(<<<SQL
CREATE TABLE `user_logs` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`ip_addr` varchar(46) NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `created_at` (`created_at`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SQL
);
}

if (!$this->foreignKeyExists('user_logs', 'fk_user_logs__user_id')) {
$this->execute(
"ALTER TABLE `user_logs` ADD CONSTRAINT `fk_user_logs__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE"
);
}
}

private function tableExists($tableName)
{
$stmt = $this->connection->executeSql("SHOW TABLES LIKE ?", $tableName);
$row = $stmt->fetch(\PDO::FETCH_NUM);

return $row !== false;
}

private function foreignKeyExists($tableName, $constraintName)
{
$stmt = $this->connection->executeSql(
"SELECT COUNT(*) AS count_value FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ? AND CONSTRAINT_TYPE = 'FOREIGN KEY'",
$tableName,
$constraintName
);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);

return $row && (int)$row['count_value'] > 0;
}
}
13 changes: 13 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ CREATE TABLE `user_blacklisted_tags` (
UNIQUE KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_logs` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`ip_addr` varchar(46) NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `created_at` (`created_at`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_records` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
Expand Down Expand Up @@ -600,6 +610,9 @@ ALTER TABLE `tag_implications`
ALTER TABLE `user_blacklisted_tags`
ADD CONSTRAINT `fk_user_bl_tags__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

ALTER TABLE `user_logs`
ADD CONSTRAINT `fk_user_logs__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

ALTER TABLE `user_records`
ADD CONSTRAINT `fk_user_records__reported_by` FOREIGN KEY (`reported_by`) REFERENCES `users` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_user_records__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
Expand Down
16 changes: 8 additions & 8 deletions db/table_schema/production/user_logs.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<?php
return array (
0 =>
0 =>
array (
'id' =>
'id' =>
array (
'type' => 'int(11) unsigned',
'default' => NULL,
),
'user_id' =>
'user_id' =>
array (
'type' => 'int(11)',
'default' => NULL,
),
'ip_addr' =>
'ip_addr' =>
array (
'type' => 'varchar(46)',
'default' => NULL,
),
'created_at' =>
'created_at' =>
array (
'type' => 'datetime',
'default' => NULL,
),
),
1 =>
1 =>
array (
'pri' =>
'pri' =>
array (
0 => 'id',
),
),
)
;
;