mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
Update UPDATE.sh
This commit is contained in:
@@ -12,3 +12,38 @@ if grep -q "^ *admin off" "$CADDYFILE"; then
|
||||
else
|
||||
echo "No 'admin off' line found or it's already commented."
|
||||
fi
|
||||
|
||||
|
||||
# add views for domain count!
|
||||
|
||||
mysql -uroot <<'EOF'
|
||||
USE panel;
|
||||
|
||||
-- Step 1: Sanitize existing data
|
||||
UPDATE users SET user_domains = '0' WHERE user_domains = '';
|
||||
|
||||
-- Step 2: Modify the column to INT
|
||||
ALTER TABLE users MODIFY COLUMN user_domains INT NOT NULL DEFAULT 0;
|
||||
|
||||
-- Step 3: Create trigger for insert
|
||||
DELIMITER //
|
||||
|
||||
CREATE TRIGGER increment_user_domains
|
||||
AFTER INSERT ON domains
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE users SET user_domains = user_domains + 1 WHERE id = NEW.user_id;
|
||||
END;
|
||||
//
|
||||
|
||||
-- Step 4: Create trigger for delete
|
||||
CREATE TRIGGER decrement_user_domains
|
||||
AFTER DELETE ON domains
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE users SET user_domains = user_domains - 1 WHERE id = OLD.user_id;
|
||||
END;
|
||||
//
|
||||
|
||||
DELIMITER ;
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user