# SocialStack v2 → v2.1 Manual Update Guide

Follow these steps in order. Do not skip the backup step.

---

## Before you start

1. Put your site in maintenance mode (or take it offline briefly).
2. **Backup your full website folder.**
3. **Backup your database** (export from phpMyAdmin or your host).
4. Keep a copy of your current `core/.env` file. You will need it later.

---

## Step 1 — Update files and folders

Upload / replace the files from **v2.1** into your live site.

### Replace these folders completely

- `assets/`
- `core/app/`
- `core/bootstrap/`
- `core/resources/`
- `core/routes/`

### Replace these root files (if present)

- `index.php`
- `.htaccess`
- `robots.txt`

### Do NOT overwrite these

- `core/.env` (your live database and site settings)
- Any uploaded user/product images you already have

### Image folders rename (important)

If you still have the old selling image folders, rename them:

- `assets/backend/images/selling-categories` → `accounts-categories`
- `assets/backend/images/selling-products` → `accounts-products`

If your database still stores old paths like `selling-categories` or `selling-products`, update those paths to `accounts-categories` / `accounts-products` after the rename.

### You do NOT need to run

- `composer update`
- `npm install`

---

## Step 2 — Run SQL (phpMyAdmin → SQL tab)

Run the commands below **one section at a time**.

### 2.1 Rename Selling tables to Accounts tables

```sql
RENAME TABLE
  `selling_categories` TO `accounts_categories`,
  `selling_accounts` TO `accounts_credentials`,
  `selling_orders` TO `accounts_orders`,
  `selling_product` TO `accounts_product`;
```

### 2.2 Create the new marketplace cart table

```sql
CREATE TABLE `marketplace_cart_items` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `product_id` bigint(20) UNSIGNED NOT NULL,
  `qty` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `marketplace_cart_items_user_product_unique` (`user_id`,`product_id`),
  KEY `marketplace_cart_items_user_id_index` (`user_id`),
  KEY `marketplace_cart_items_product_id_index` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
```

### 2.3 Add new settings columns

```sql
ALTER TABLE `settings`
  ADD `admin_prefix` varchar(50) NOT NULL DEFAULT 'backend' AFTER `website_name`,
  ADD `cron_secret_key` varchar(255) DEFAULT NULL AFTER `copyright_text`,
  ADD `frontend_pages` tinyint(4) NOT NULL DEFAULT 1 AFTER `user_login`;
```

### 2.4 Add client_reference to SMM and VTU orders

```sql
ALTER TABLE `smm_orders`
  ADD `client_reference` varchar(64) DEFAULT NULL AFTER `provider_order_id`,
  ADD UNIQUE KEY `smm_orders_client_reference_unique` (`client_reference`);

ALTER TABLE `vtu_orders`
  ADD `client_reference` varchar(64) DEFAULT NULL AFTER `provider_plan_id`,
  ADD UNIQUE KEY `vtu_orders_client_reference_unique` (`client_reference`);
```

### 2.5 Set your cron secret key

Replace `CHANGE_THIS_TO_A_LONG_RANDOM_SECRET` with your own secret.

```sql
UPDATE `settings`
SET `cron_secret_key` = 'CHANGE_THIS_TO_A_LONG_RANDOM_SECRET'
WHERE `id` = 1;
```

Optional: change your admin URL prefix (default is `backend`).

```sql
UPDATE `settings`
SET `admin_prefix` = 'backend'
WHERE `id` = 1;
```

---

## Step 3 — After the update

1. Clear cache if your host allows it (or delete files inside `core/storage/framework/cache` carefully).
2. Log in to admin and check:
   - Settings (admin prefix, cron key, frontend pages)
   - Accounts section (old Selling menu is now Accounts)
   - Marketplace cart / checkout
   - SMM and VTU orders
3. Update your cron job URL so it includes the secret key, for example:
   - `https://yoursite.com/cron/...?key=YOUR_CRON_SECRET`
4. Note URL changes:
   - Old: `/selling`
   - New: `/accounts`
   - Admin path uses `admin_prefix` (default `/backend`)

---

## Quick checklist

- [ ] Full files + database backup done
- [ ] Kept live `core/.env`
- [ ] Replaced app folders listed above
- [ ] Renamed selling image folders to accounts folders
- [ ] Ran all SQL sections
- [ ] Set `cron_secret_key`
- [ ] Updated cron URL with the secret key
- [ ] Tested login, accounts, marketplace, SMM, VTU

---

## If something goes wrong

1. Restore your website folder backup.
2. Restore your database backup.
3. Try again carefully, one step at a time.

Do **not** import the full `socialstackv2.1.sql` dump over a live site. That would wipe your real data. Only run the SQL commands in this guide.
