Skip to content

Commit bdc8caf

Browse files
committed
newer Laravel uses seconds instead of minutes for cache (see #9)
1 parent c8aaafc commit bdc8caf

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Allows you to export JSON files of your most important data (questions, answers,
66
1. I think this project requires PHP 7.3 or later, so be sure that your system complies.
77
1. Sign up at https://stackapps.com/apps/oauth/register to receive a Client ID, Client Secret, and Key. (It's free, easy, and fast.)
88
1. Create a Laravel project, and make sure that it works: https://laravel.com/docs/6.0/installation
9-
1. Add this package into your Laravel project: `vagrant@vboxHomestead:~/Code/MyLaravelProject$ composer require ryancwalsh/stack-exchange-backup-laravel:^2.0.0`
9+
1. Add this package into your Laravel project: `vagrant@vboxHomestead:~/Code/MyLaravelProject$ composer require ryancwalsh/stack-exchange-backup-laravel:^2.0.1`
1010
1. Run `php artisan vendor:publish`, and if it gives you a choice, choose to publish from this package.
1111
1. Edit your Laravel project's `.env` file to have your own StackApps values. A non-working sample is below.
1212
1. Run `php artisan exportStackExchange`. There are also these options available:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ryancwalsh/stack-exchange-backup-laravel",
33
"description": "My aim is to back up all of my questions and answers and anything else valuable in my accounts across all of the StackExchange sites (StackOverflow, SuperUser, https://apple.stackexchange.com/, https://askubuntu.com/, etc).",
44
"type": "package",
5-
"version": "2.0.0",
5+
"version": "2.0.1",
66
"require": {
77
"guzzlehttp/guzzle": "^6.3",
88
"php": "^7.3",

src/ExportStackExchangeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public function handleStackExchangeCode() {
7777
$codePasted = $this->ask('Then, the browser will bounce to a new URL. Copy the value of the `code` parameter in the URL. Paste it here:');
7878
$code = str_replace(self::SE_URL_BEGINNING, '', $codePasted); //just in case the user accidentally pasted the entire URL instead of just the `code` parameter.
7979
Log::debug('$code=' . $code);
80-
Cache::put(self::CODE_CACHE_KEY, $code, $this->exportStackExchangeHelper::SESSION_MINS);
80+
Cache::put(self::CODE_CACHE_KEY, $code, $this->exportStackExchangeHelper::SESSION_SECONDS);
8181
Cache::forget($this->exportStackExchangeHelper::ACCESS_TOKEN_CACHE_KEY);
82-
$this->info('Code now saved to cache for ' . $this->exportStackExchangeHelper::SESSION_MINS . ' minutes: ' . Cache::get(self::CODE_CACHE_KEY));
82+
$this->info('Code now saved to cache for ' . $this->exportStackExchangeHelper::SESSION_SECONDS . ' minutes: ' . Cache::get(self::CODE_CACHE_KEY));
8383
}
8484
$this->exportStackExchangeHelper->setCode($code);
8585
}

src/ExportStackExchangeHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class ExportStackExchangeHelper {
1111

1212
const API_URL = 'https://api.stackexchange.com'; #https://api.stackexchange.com/docs
13-
const SESSION_MINS = 60;
13+
const SESSION_SECONDS = 60 * 60;
1414
const ACCESS_TOKEN_CACHE_KEY = 'stackapps_access_token';
1515
const APP_FOLDER = 'app/';
1616
const SE_FOLDER = 'StackExchange/';
@@ -66,7 +66,7 @@ public function getOauthUrl() {
6666
* @return string
6767
*/
6868
public function getAccessTokenJson() {
69-
$accessTokenResponseJsonString = Cache::remember(self::ACCESS_TOKEN_CACHE_KEY, self::SESSION_MINS, function () {//https://laravel.com/docs/5.6/cache#retrieving-items-from-the-cache
69+
$accessTokenResponseJsonString = Cache::remember(self::ACCESS_TOKEN_CACHE_KEY, self::SESSION_SECONDS, function () {//https://laravel.com/docs/5.6/cache#retrieving-items-from-the-cache
7070
$url = 'https://stackoverflow.com/oauth/access_token/json'; //https://api.stackexchange.com/docs/authentication
7171
$payload = [
7272
'form_params' => [
@@ -103,7 +103,7 @@ public function getAccessTokenFromJson($accessTokenResponseJsonString) {
103103
* @param int $cacheMinutes
104104
* @return string
105105
*/
106-
public function get($uri = '', array $options = [], $cacheMinutes = self::SESSION_MINS) {
106+
public function get($uri = '', array $options = [], $cacheMinutes = self::SESSION_SECONDS) {
107107
$cacheKey = sha1($uri . json_encode($options));
108108
$response = Cache::remember($cacheKey, $cacheMinutes, function () use ($uri, $options) {//https://laravel.com/docs/5.6/cache#retrieving-items-from-the-cache
109109
$accessTokenResponseJsonString = $this->getAccessTokenJson();

0 commit comments

Comments
 (0)