419 Page Expired When Trying to Save Labels for Pages #4874

Closed
opened 2026-02-05 09:22:47 +03:00 by OVERLORD · 19 comments
Owner

Originally created by @mschoon85 on GitHub (Jul 15, 2024).

Describe the Bug

Hi @ssddanbrown

We are experiencing intermittent issues when saving a page after adding labels. The problem occurs frequently but not consistently. If it were a settings issue, it would either always work or never work. This might be worth investigating, as it can be quite annoying for our users.

Kind regards,

Michel

Steps to Reproduce

  1. Create a new page
  2. Add multiple labels
  3. Save the page
  4. Repeat until the error occurs

Expected Behaviour

No error

Screenshots or Additional Context

page-expired

Browser Details

MS Edge

Exact BookStack Version

24.05.1

Originally created by @mschoon85 on GitHub (Jul 15, 2024). ### Describe the Bug Hi @ssddanbrown We are experiencing intermittent issues when saving a page after adding labels. The problem occurs frequently but not consistently. If it were a settings issue, it would either always work or never work. This might be worth investigating, as it can be quite annoying for our users. Kind regards, Michel ### Steps to Reproduce 1. Create a new page 2. Add multiple labels 3. Save the page 4. Repeat until the error occurs ### Expected Behaviour No error ### Screenshots or Additional Context ![page-expired](https://github.com/user-attachments/assets/a44a2893-14aa-4123-be34-bf2b6c8e3d87) ### Browser Details MS Edge ### Exact BookStack Version 24.05.1
OVERLORD added the 🐛 Bug label 2026-02-05 09:22:47 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Jul 15, 2024):

Hi @mschoon85,
This will typically be something specific to your environment/scenario, and can often be due to another requested being made, and failing, in the background for some reason.

Are you familiar with the browser development tools? If so, it would be useful if you could open the console tab, then refresh then page (when in the editor), then report back the messages shown (if any).

@ssddanbrown commented on GitHub (Jul 15, 2024): Hi @mschoon85, This will typically be something specific to your environment/scenario, and can often be due to another requested being made, and failing, in the background for some reason. Are you familiar with the browser development tools? If so, it would be useful if you could open the console tab, then refresh then page (when in the editor), then report back the messages shown (if any).
Author
Owner

@mschoon85 commented on GitHub (Jul 15, 2024):

Hi @ssddanbrown,

When I open the page and there is nothing in the console, adding the labels and then saving the page works without any issues. However, when I see this message in the console after clicking on edit, the saving of labels fails:

Before saving:

manifest.json:1 

        GET
https://URL/manifest.json
500 (Internal Server Error)
manifest.json:1  Manifest: Line: 1, column: 1, Syntax error.
[NEW] Explain Console errors by using Copilot in Edge: click
         to explain an error. 
        Learn more

After saving:

sleutelen-aan-een-auto-op-de-openbare-weg:1 

        POST
https://URL/books/kcc-team-toezicht-en-handhaving/page/sleutelen-aan-een-auto-op-de-openbare-weg
419
[NEW] Explain Console errors by using Copilot in Edge: click
         to explain an error. 
        Learn more

Click here url: https://learn.microsoft.com/nl-nl/microsoft-edge/devtools-guide-chromium/console/copilot-explain-console#the-explain-this-error-feature

@mschoon85 commented on GitHub (Jul 15, 2024): Hi @ssddanbrown, When I open the page and there is nothing in the console, adding the labels and then saving the page works without any issues. However, when I see this message in the console after clicking on edit, the saving of labels fails: **Before saving:** ``` manifest.json:1 GET https://URL/manifest.json 500 (Internal Server Error) manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. [NEW] Explain Console errors by using Copilot in Edge: click to explain an error. Learn more ``` **After saving:** ``` sleutelen-aan-een-auto-op-de-openbare-weg:1 POST https://URL/books/kcc-team-toezicht-en-handhaving/page/sleutelen-aan-een-auto-op-de-openbare-weg 419 [NEW] Explain Console errors by using Copilot in Edge: click to explain an error. Learn more ``` Click here url: https://learn.microsoft.com/nl-nl/microsoft-edge/devtools-guide-chromium/console/copilot-explain-console#the-explain-this-error-feature
Author
Owner

@mschoon85 commented on GitHub (Jul 15, 2024):

I have more information on the second attempt. During the first attempt, we did not wait long enough for the other errors to appear. They show up as soon as I add a label on the second attempt.

console_log2

@mschoon85 commented on GitHub (Jul 15, 2024): I have more information on the second attempt. During the first attempt, we did not wait long enough for the other errors to appear. They show up as soon as I add a label on the second attempt. ![console_log2](https://github.com/user-attachments/assets/c29ad908-8b72-4ca4-a7ab-09e16d132031)
Author
Owner

@mschoon85 commented on GitHub (Jul 15, 2024):

console3
console3_1

@mschoon85 commented on GitHub (Jul 15, 2024): ![console3](https://github.com/user-attachments/assets/07486011-5b4e-4cde-bc9c-21ef53436fff) ![console3_1](https://github.com/user-attachments/assets/dca456fe-93cd-46b0-8826-ffd9d9e9ef8d)
Author
Owner

@mschoon85 commented on GitHub (Jul 15, 2024):

I also notice that when I get the error message and then press the back button in the browser, SSO logs in again.

@mschoon85 commented on GitHub (Jul 15, 2024): I also notice that when I get the error message and then press the back button in the browser, SSO logs in again.
Author
Owner

@ssddanbrown commented on GitHub (Jul 15, 2024):

Thanks for the info @mschoon85.
Can you watch your BookStack error log file and report back any errors that get added when you go through the process of adding new tags to a page.

@ssddanbrown commented on GitHub (Jul 15, 2024): Thanks for the info @mschoon85. Can you watch your [BookStack error log file](https://www.bookstackapp.com/docs/admin/debugging/#error-log-file) and report back any errors that get added when you go through the process of adding new tags to a page.
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

@ssddanbrown, Please find attached the logfile from the period when I was attempting to reproduce the issue. There were many errors in the console, but I was also able to save the page several times without any console errors. Eventually, I was able to reproduce the 419 Page Expired error, which should be at the end of the logfile.

laravel - Copy.log

@mschoon85 commented on GitHub (Jul 16, 2024): @ssddanbrown, Please find attached the logfile from the period when I was attempting to reproduce the issue. There were many errors in the console, but I was also able to save the page several times without any console errors. Eventually, I was able to reproduce the 419 Page Expired error, which should be at the end of the logfile. [laravel - Copy.log](https://github.com/user-attachments/files/16245606/laravel.-.Copy.log)
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (Connection: mysql, SQL: select * from `users` where `system_name` = public limit 1)
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (Connection: mysql, SQL: select * from `users` where `system_name` = public limit 1) (View: D:\\Apache24\\htdocs\\bookstack\\resources\\views\\layouts\\base.blade.php)

These are the two errors I have found. I do not have a user named 'forge' in the database. This user is also unknown to me. Could it be something that BookStack uses? The database user for BookStack is named 'Bookstack'.

@mschoon85 commented on GitHub (Jul 16, 2024): ``` SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (Connection: mysql, SQL: select * from `users` where `system_name` = public limit 1) ``` ``` SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (Connection: mysql, SQL: select * from `users` where `system_name` = public limit 1) (View: D:\\Apache24\\htdocs\\bookstack\\resources\\views\\layouts\\base.blade.php) ``` These are the two errors I have found. I do not have a user named 'forge' in the database. This user is also unknown to me. Could it be something that BookStack uses? The database user for BookStack is named 'Bookstack'.
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

I found at least one reference to a 'forge' user:

D:\Apache24\htdocs\bookstack\app\Config\database.php (2 hits)
Line 65: 'database' => env('DB_DATABASE', 'forge'),
Line 66: 'username' => env('DB_USERNAME', 'forge'),

It seems that is is set correctly:

The 'forge' user you see in the error messages is a default setting in Laravel. Laravel often uses the 'forge' user as the default database user in its configuration files, especially if the environment variables are not correctly set or if the configuration cache contains outdated values.

Causes and Solutions:
Default Setting in Laravel:

When you set up a new Laravel installation, Laravel configures the database to use the 'forge' user by default. This is intended as a placeholder until you configure your own database settings.

@mschoon85 commented on GitHub (Jul 16, 2024): I found at least one reference to a 'forge' user: D:\Apache24\htdocs\bookstack\app\Config\database.php (2 hits) Line 65: 'database' => env('DB_DATABASE', 'forge'), Line 66: 'username' => env('DB_USERNAME', 'forge'), It seems that is is set correctly: > The 'forge' user you see in the error messages is a default setting in Laravel. Laravel often uses the 'forge' user as the default database user in its configuration files, especially if the environment variables are not correctly set or if the configuration cache contains outdated values. > > Causes and Solutions: > Default Setting in Laravel: > > When you set up a new Laravel installation, Laravel configures the database to use the 'forge' user by default. This is intended as a placeholder until you configure your own database settings.
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

I was advised to clear the caches, but I encountered the following error:

D:\Apache24\htdocs\bookstack>php artisan config:clear

   INFO  Configuration cache cleared successfully.


D:\Apache24\htdocs\bookstack>php artisan cache:clear

   INFO  Application cache cleared successfully.


D:\Apache24\htdocs\bookstack>php artisan config:cache
PHP Fatal error:  Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14) in D:\Apache24\htdocs\bookstack\themes\custom\functions.php on line 26

In functions.php line 26:

  Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14
  )



In functions.php line 26:

  Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14
  )

@mschoon85 commented on GitHub (Jul 16, 2024): I was advised to clear the caches, but I encountered the following error: ``` D:\Apache24\htdocs\bookstack>php artisan config:clear INFO Configuration cache cleared successfully. D:\Apache24\htdocs\bookstack>php artisan cache:clear INFO Application cache cleared successfully. D:\Apache24\htdocs\bookstack>php artisan config:cache PHP Fatal error: Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14) in D:\Apache24\htdocs\bookstack\themes\custom\functions.php on line 26 In functions.php line 26: Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14 ) In functions.php line 26: Cannot redeclare autoSortBook() (previously declared in D:\Apache24\htdocs\bookstack\themes\custom\functions.php:14 ) ```
Author
Owner

@ssddanbrown commented on GitHub (Jul 16, 2024):

Ah, a windows based apache environment.
Yeah, that can be prone to thread safety issues which is likely what's occurring here since we can see the config reflecting defaults.

Config caching can be a workaround but that will conflict with custom theme functions (we don't officially advise/document config caching) unless that's specifically handled in the theme code by wrapping functions in exist checks, eg:

if (!function_exists('autoSortBook')) {
    function autoSortBook(Book $book): void {
        /// function code here
    }
}

We could maybe look to make the theme work with cache (load functions.php only once) and/or update config usage to avoid non-thread-safe functions but some further testing required there to properly check potential impacts.

Dev references

@ssddanbrown commented on GitHub (Jul 16, 2024): Ah, a windows based apache environment. Yeah, that can be prone to thread safety issues which is likely what's occurring here since we can see the config reflecting defaults. Config caching can be a workaround but that will conflict with custom theme functions (we don't officially advise/document config caching) unless that's specifically handled in the theme code by wrapping functions in exist checks, eg: ```php if (!function_exists('autoSortBook')) { function autoSortBook(Book $book): void { /// function code here } } ``` We could maybe look to make the theme work with cache (load functions.php only once) and/or update config usage to avoid non-thread-safe functions but some further testing required there to properly check potential impacts. ### Dev references - https://github.com/BookStackApp/BookStack/blob/bba7dcce49394f478bd401486a2d8cba23ff79ac/app/Theming/ThemeService.php#L77 - https://github.com/laravel/framework/pull/28908 - https://github.com/laravel/framework/pull/28740
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

@ssddanbrown I don't believe the theme is causing the 419 error. This issue was occurring even before we implemented the autosort 'hack'. After every Bookstack update, we clear those three caches. Last Friday, we implemented the autosort 'hack' after payment. It would be great to make this compatible with clearing the 'php artisan config' command as well.

How should we proceed with investigating the 419 issue? Did you see all my previous messages with the logs, etc.?

@mschoon85 commented on GitHub (Jul 16, 2024): @ssddanbrown I don't believe the theme is causing the 419 error. This issue was occurring even before we implemented the autosort 'hack'. After every Bookstack update, we clear those three caches. Last Friday, we implemented the autosort 'hack' after payment. It would be great to make this compatible with clearing the 'php artisan config' command as well. How should we proceed with investigating the 419 issue? Did you see all my previous messages with the logs, etc.?
Author
Owner

@ssddanbrown commented on GitHub (Jul 16, 2024):

@mschoon85 I'm not saying the theme is causing it, but that caching can help in thread-safety-prone environments like yours, which you can't run since the combined use and implementation of the theme system is not compatible.

If you wrap your theme functions like shown above, you should be able to cache the config to avoid config thread-safety issues. You'll need to remember to re-cache (or clear) this config cache upon any future updates, or when making any .env changes in the future.

@ssddanbrown commented on GitHub (Jul 16, 2024): @mschoon85 I'm not saying the theme is causing it, but that caching can help in thread-safety-prone environments like yours, which you can't run since the combined use and implementation of the theme system is not compatible. If you wrap your theme functions like shown above, you should be able to cache the config to avoid config thread-safety issues. You'll need to remember to re-cache (or clear) this config cache upon any future updates, or when making any `.env` changes in the future.
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

@ssddanbrown

Wrapping the function as shown below will result in an error:

 if (!function_exists('autoSortBook')) {
    function autoSortBook(Book $book): void {
		
function autoSortBook(Book $book): void {
    $chapters = $book->chapters()->orderBy('name', 'asc')->get(['id', 'priority']);
    $pages = $book->pages()->orderBy('name', 'asc')
        ->where('draft', '=', false)
        ->get(['id', 'priority']);
    $chapterCount = $chapters->count();

    foreach ($chapters as $index => $chapter) {
        $chapter->priority = $index;
        $chapter->save();
    }

    foreach ($pages as $index => $page) {
        $page->priority = $chapterCount + $index;
        $page->save();
    }
}
   }
}
@mschoon85 commented on GitHub (Jul 16, 2024): @ssddanbrown Wrapping the function as shown below will result in an error: ``` if (!function_exists('autoSortBook')) { function autoSortBook(Book $book): void { function autoSortBook(Book $book): void { $chapters = $book->chapters()->orderBy('name', 'asc')->get(['id', 'priority']); $pages = $book->pages()->orderBy('name', 'asc') ->where('draft', '=', false) ->get(['id', 'priority']); $chapterCount = $chapters->count(); foreach ($chapters as $index => $chapter) { $chapter->priority = $index; $chapter->save(); } foreach ($pages as $index => $page) { $page->priority = $chapterCount + $index; $page->save(); } } } } ```
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

I did it this way, and now it works:

D:\Apache24\htdocs\bookstack>php artisan config:cache

   INFO  Configuration cached successfully.
if (!function_exists('autoSortBook')) {
    function autoSortBook(Book $book): void {
        $chapters = $book->chapters()->orderBy('name', 'asc')->get(['id', 'priority']);
        $pages = $book->pages()->orderBy('name', 'asc')
            ->where('draft', '=', false)
            ->get(['id', 'priority']);
        $chapterCount = $chapters->count();

        foreach ($chapters as $index => $chapter) {
            $chapter->priority = $index;
            $chapter->save();
        }

        foreach ($pages as $index => $page) {
            $page->priority = $chapterCount + $index;
            $page->save();
        }
    }
}

@mschoon85 commented on GitHub (Jul 16, 2024): I did it this way, and now it works: ``` D:\Apache24\htdocs\bookstack>php artisan config:cache INFO Configuration cached successfully. ``` ``` if (!function_exists('autoSortBook')) { function autoSortBook(Book $book): void { $chapters = $book->chapters()->orderBy('name', 'asc')->get(['id', 'priority']); $pages = $book->pages()->orderBy('name', 'asc') ->where('draft', '=', false) ->get(['id', 'priority']); $chapterCount = $chapters->count(); foreach ($chapters as $index => $chapter) { $chapter->priority = $index; $chapter->save(); } foreach ($pages as $index => $page) { $page->priority = $chapterCount + $index; $page->save(); } } } ```
Author
Owner

@mschoon85 commented on GitHub (Jul 16, 2024):

Perhaps the functions.php file on https://www.bookstackapp.com/hacks/autosort-tagged-books needs the above addition as well.

@mschoon85 commented on GitHub (Jul 16, 2024): Perhaps the functions.php file on https://www.bookstackapp.com/hacks/autosort-tagged-books needs the above addition as well.
Author
Owner

@mschoon85 commented on GitHub (Jul 17, 2024):

@ssddanbrown , It appears that the issue has been resolved by wrapping the function and clearing those three caches. I am currently unable to reproduce the problem.

@mschoon85 commented on GitHub (Jul 17, 2024): @ssddanbrown , It appears that the issue has been resolved by wrapping the function and clearing those three caches. I am currently unable to reproduce the problem.
Author
Owner

@mschoon85 commented on GitHub (Jul 17, 2024):

I also noticed that the php artisan config:cache command was missing from my update script. It would be beneficial to add this command to the list on the BookStack update documentation (https://www.bookstackapp.com/docs/admin/updates/).

For your reference, or for anyone else who might be interested, here is my (powershell) update script, which includes file and database backup:

Details

# Define log file at the script scope
$script:LogFile = "D:\Update\Logs\log_PROD_$(Get-Date -Format "yyyyMMdd_HHmmss").txt"

Function Check-RunAsAdministrator()
{
  # Get current user context
  $CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  
  # Check if user is running the script as a member of Administrator Group
  if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
  {
       Add-Content -Path $script:LogFile -Value "Script is running with Administrator privileges!"
  }
  else
    {
       # Create a new Elevated process to Start PowerShell
       $ElevatedProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
 
       # Specify the current script path and name as a parameter
       $ElevatedProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
 
       # Set the Process to elevated
       $ElevatedProcess.Verb = "runas"
 
       # Start the new elevated process
       [System.Diagnostics.Process]::Start($ElevatedProcess)
 
       Add-Content -Path $script:LogFile -Value "Script is being run with elevated privileges."
       
       # Exit from the current, unelevated, process
       Exit
    }
}

# Check if Script is running with Elevated Privileges
Check-RunAsAdministrator

# Define the date and time format
$datetime = Get-Date -Format "yyyyMMdd_HHmmss"
Add-Content -Path $script:LogFile -Value "Defined date and time format: $datetime"


# Define the source, temporary and destination paths
$source = "D:\Apache24\htdocs\bookstack"
$tempDestination = "D:\Backups\temp\bookstack_backup"
$datetime = Get-Date -Format "yyyyMMddHHmmss"
$destination = "D:\Backups\bookstack_backup_PROD_$datetime.zip"
Add-Content -Path $script:LogFile -Value "Defined source: $source, temporary: $tempDestination and destination: $destination paths."


# Message on screen that Robocopy is starting
Write-Host "The backup process is starting..."
    
# Copy files using Robocopy
try {
    # Run Robocopy and store the output in the variable $output
    $output = Robocopy $source $tempDestination /E /COPYALL /R:3 /W:10 2>&1

    # Display the Robocopy output on the screen
    $output | Write-Host

    # Add the Robocopy output to the log file
    Add-Content -Path $script:LogFile -Value $output

    # Add a confirmation message to the log file
    Add-Content -Path $script:LogFile -Value "Copied files from $source to $tempDestination"
} catch {
    Add-Content -Path $script:LogFile -Value "Error copying files: $_"
    exit
}

Clear-Host

# Create a zip archive from the temporary location
try {
    Compress-Archive -Path $tempDestination -DestinationPath $destination 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Created a zip archive from $tempDestination to $destination"
} catch {
    Add-Content -Path $script:LogFile -Value "Error creating zip archive: $_"
    exit
}

# Clean up the temporary directory
Remove-Item -Path $tempDestination -Recurse -Force
Add-Content -Path $script:LogFile -Value "Cleaned up the temporary files at $tempDestination"


# Load encrypted credentials from a file
try {
    $credential = Import-Clixml -Path "D:\Update\SecureCredentials.xml" 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Loaded encrypted credentials from a file."
} catch {
    Add-Content -Path $script:LogFile -Value "Error loading encrypted credentials: $_"
}

# Get the username and password from the credential object
$user = $credential.UserName
$pass = $credential.GetNetworkCredential().Password
Add-Content -Path $script:LogFile -Value "Extracted the username and password from the credential object."

# Run mysqldump with the username and password
try {
    & 'C:\Program Files\MariaDB 10.9\bin\mysqldump.exe' --user=$user --password=$pass --databases bookstack > "D:\Backups\database_backup_PROD_$datetime.sql" 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Ran mysqldump with the provided username and password."
} catch {
    Add-Content -Path $script:LogFile -Value "Error running mysqldump: $_"
}

# Change to D drive
try {
    Set-Location -Path D:\ 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Changed location to D drive."
} catch {
    Add-Content -Path $script:LogFile -Value "Error changing location to D drive: $_"
}

# Change to specific directory
try {
    Set-Location -Path .\Apache24\htdocs\bookstack 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Changed location to .\Apache24\htdocs\bookstack."
} catch {
    Add-Content -Path $script:LogFile -Value "Error changing location to .\Apache24\htdocs\bookstack: $_"
}

# Prompt the user to check if the backup was successful
$checkBackup = Read-Host -Prompt "Is the backup of the folder and the database successfully made? Please check in D:\Backups. (yes/no)"

if ($checkBackup -eq "yes") {
    # Pull from git
    try {
        git pull origin release 2>&1 | Tee-Object -Variable output
        Add-Content -Path $script:LogFile -Value "Pulled updates from git."
    } catch {
        Add-Content -Path $script:LogFile -Value "Error pulling updates from git: $_"
    }
} else {
    Add-Content -Path $script:LogFile -Value "Update cancelled by the user due to backup concerns."
    Write-Host "Update cancelled. Please check the backup and run the script again."
}

# Install composer dependencies
try {
    composer install --no-dev 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Installed composer dependencies."
} catch {
    Add-Content -Path $script:LogFile -Value "Error installing composer dependencies: $_"
}

# Run artisan migrations with --force
try {
    php artisan migrate --force 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Ran artisan migrations with --force."
} catch {
    Add-Content -Path $script:LogFile -Value "Error running artisan migrations: $_"
}

# Clear application cache
try {
    php artisan cache:clear 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Cleared application cache."
} catch {
    Add-Content -Path $script:LogFile -Value "Error clearing application cache: $_"
}

# Clear configuration cache
try {
    php artisan config:clear 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Cleared configuration cache."
} catch {
    Add-Content -Path $script:LogFile -Value "Error clearing configuration cache: $_"
}

# Clear compiled view files
try {
    php artisan view:clear 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Cleared compiled view files."
} catch {
    Add-Content -Path $script:LogFile -Value "Error clearing compiled view files: $_"
}

# Cache the configuration
try {
    php artisan config:cache 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Cached configuration."
} catch {
    Add-Content -Path $script:LogFile -Value "Error caching configuration: $_"
}

# Clean up images with force option and auto-confirm
try {
    echo "yes" | php artisan bookstack:cleanup-images --force 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Cleaned up images with force and auto-confirmation."
} catch {
    Add-Content -Path $script:LogFile -Value "Error cleaning up images with force: $_"
}

# Regenerate search index
try {
    php artisan bookstack:regenerate-search 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Regenerated search index."
} catch {
    Add-Content -Path $script:LogFile -Value "Error regenerating search index: $_"
}

# Regenerate references
try {
    php artisan bookstack:regenerate-references 2>&1 | Tee-Object -Variable output
    Add-Content -Path $script:LogFile -Value "Regenerated references."
} catch {
    Add-Content -Path $script:LogFile -Value "Error regenerating references: $_"
}

@mschoon85 commented on GitHub (Jul 17, 2024): I also noticed that the php artisan config:cache command was missing from my update script. It would be beneficial to add this command to the list on the BookStack update documentation (https://www.bookstackapp.com/docs/admin/updates/). For your reference, or for anyone else who might be interested, here is my (powershell) update script, which includes file and database backup: <details><summary>Details</summary> <p> ```powershell # Define log file at the script scope $script:LogFile = "D:\Update\Logs\log_PROD_$(Get-Date -Format "yyyyMMdd_HHmmss").txt" Function Check-RunAsAdministrator() { # Get current user context $CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) # Check if user is running the script as a member of Administrator Group if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { Add-Content -Path $script:LogFile -Value "Script is running with Administrator privileges!" } else { # Create a new Elevated process to Start PowerShell $ElevatedProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell"; # Specify the current script path and name as a parameter $ElevatedProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'" # Set the Process to elevated $ElevatedProcess.Verb = "runas" # Start the new elevated process [System.Diagnostics.Process]::Start($ElevatedProcess) Add-Content -Path $script:LogFile -Value "Script is being run with elevated privileges." # Exit from the current, unelevated, process Exit } } # Check if Script is running with Elevated Privileges Check-RunAsAdministrator # Define the date and time format $datetime = Get-Date -Format "yyyyMMdd_HHmmss" Add-Content -Path $script:LogFile -Value "Defined date and time format: $datetime" # Define the source, temporary and destination paths $source = "D:\Apache24\htdocs\bookstack" $tempDestination = "D:\Backups\temp\bookstack_backup" $datetime = Get-Date -Format "yyyyMMddHHmmss" $destination = "D:\Backups\bookstack_backup_PROD_$datetime.zip" Add-Content -Path $script:LogFile -Value "Defined source: $source, temporary: $tempDestination and destination: $destination paths." # Message on screen that Robocopy is starting Write-Host "The backup process is starting..." # Copy files using Robocopy try { # Run Robocopy and store the output in the variable $output $output = Robocopy $source $tempDestination /E /COPYALL /R:3 /W:10 2>&1 # Display the Robocopy output on the screen $output | Write-Host # Add the Robocopy output to the log file Add-Content -Path $script:LogFile -Value $output # Add a confirmation message to the log file Add-Content -Path $script:LogFile -Value "Copied files from $source to $tempDestination" } catch { Add-Content -Path $script:LogFile -Value "Error copying files: $_" exit } Clear-Host # Create a zip archive from the temporary location try { Compress-Archive -Path $tempDestination -DestinationPath $destination 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Created a zip archive from $tempDestination to $destination" } catch { Add-Content -Path $script:LogFile -Value "Error creating zip archive: $_" exit } # Clean up the temporary directory Remove-Item -Path $tempDestination -Recurse -Force Add-Content -Path $script:LogFile -Value "Cleaned up the temporary files at $tempDestination" # Load encrypted credentials from a file try { $credential = Import-Clixml -Path "D:\Update\SecureCredentials.xml" 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Loaded encrypted credentials from a file." } catch { Add-Content -Path $script:LogFile -Value "Error loading encrypted credentials: $_" } # Get the username and password from the credential object $user = $credential.UserName $pass = $credential.GetNetworkCredential().Password Add-Content -Path $script:LogFile -Value "Extracted the username and password from the credential object." # Run mysqldump with the username and password try { & 'C:\Program Files\MariaDB 10.9\bin\mysqldump.exe' --user=$user --password=$pass --databases bookstack > "D:\Backups\database_backup_PROD_$datetime.sql" 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Ran mysqldump with the provided username and password." } catch { Add-Content -Path $script:LogFile -Value "Error running mysqldump: $_" } # Change to D drive try { Set-Location -Path D:\ 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Changed location to D drive." } catch { Add-Content -Path $script:LogFile -Value "Error changing location to D drive: $_" } # Change to specific directory try { Set-Location -Path .\Apache24\htdocs\bookstack 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Changed location to .\Apache24\htdocs\bookstack." } catch { Add-Content -Path $script:LogFile -Value "Error changing location to .\Apache24\htdocs\bookstack: $_" } # Prompt the user to check if the backup was successful $checkBackup = Read-Host -Prompt "Is the backup of the folder and the database successfully made? Please check in D:\Backups. (yes/no)" if ($checkBackup -eq "yes") { # Pull from git try { git pull origin release 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Pulled updates from git." } catch { Add-Content -Path $script:LogFile -Value "Error pulling updates from git: $_" } } else { Add-Content -Path $script:LogFile -Value "Update cancelled by the user due to backup concerns." Write-Host "Update cancelled. Please check the backup and run the script again." } # Install composer dependencies try { composer install --no-dev 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Installed composer dependencies." } catch { Add-Content -Path $script:LogFile -Value "Error installing composer dependencies: $_" } # Run artisan migrations with --force try { php artisan migrate --force 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Ran artisan migrations with --force." } catch { Add-Content -Path $script:LogFile -Value "Error running artisan migrations: $_" } # Clear application cache try { php artisan cache:clear 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Cleared application cache." } catch { Add-Content -Path $script:LogFile -Value "Error clearing application cache: $_" } # Clear configuration cache try { php artisan config:clear 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Cleared configuration cache." } catch { Add-Content -Path $script:LogFile -Value "Error clearing configuration cache: $_" } # Clear compiled view files try { php artisan view:clear 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Cleared compiled view files." } catch { Add-Content -Path $script:LogFile -Value "Error clearing compiled view files: $_" } # Cache the configuration try { php artisan config:cache 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Cached configuration." } catch { Add-Content -Path $script:LogFile -Value "Error caching configuration: $_" } # Clean up images with force option and auto-confirm try { echo "yes" | php artisan bookstack:cleanup-images --force 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Cleaned up images with force and auto-confirmation." } catch { Add-Content -Path $script:LogFile -Value "Error cleaning up images with force: $_" } # Regenerate search index try { php artisan bookstack:regenerate-search 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Regenerated search index." } catch { Add-Content -Path $script:LogFile -Value "Error regenerating search index: $_" } # Regenerate references try { php artisan bookstack:regenerate-references 2>&1 | Tee-Object -Variable output Add-Content -Path $script:LogFile -Value "Regenerated references." } catch { Add-Content -Path $script:LogFile -Value "Error regenerating references: $_" } ``` </p> </details>
Author
Owner

@ssddanbrown commented on GitHub (Jul 17, 2024):

@mschoon85 I don't advise config caching in our guidance to avoid the impacts in support it can introduce. All this is rarely an issue in realistic production environments, it's only really relevant in edge cases (like Apache on windows, which I'd consider more of a dev environment to be honest).

I've opened up #5126 to look into removing the thread unsafe functions, to avoid this at a more fundamental layer.
And I've opened #5125 for improving how the theme system works with commands like config:cache (even if undocumented).
I'll therefore close this off.

@ssddanbrown commented on GitHub (Jul 17, 2024): @mschoon85 I don't advise config caching in our guidance to avoid the impacts in support it can introduce. All this is rarely an issue in realistic production environments, it's only really relevant in edge cases (like Apache on windows, which I'd consider more of a dev environment to be honest). I've opened up #5126 to look into removing the thread unsafe functions, to avoid this at a more fundamental layer. And I've opened #5125 for improving how the theme system works with commands like config:cache (even if undocumented). I'll therefore close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#4874