Skip to content

Commit

Permalink
Pass config values to Sheets instead of internally retrieving them
Browse files Browse the repository at this point in the history
This allows us to instantiate a different `Sheets` instance for
interacting with a different Google Sheet.
  • Loading branch information
forevermatt committed Sep 5, 2024
1 parent b4829f4 commit 7cf39d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 0 additions & 6 deletions application/common/components/Sheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class Sheets extends Component
*/
public function init()
{
$this->applicationName = \Yii::$app->params['google']['applicationName'];
$this->jsonAuthFilePath = \Yii::$app->params['google']['jsonAuthFilePath'];
$this->jsonAuthString = \Yii::$app->params['google']['jsonAuthString'];
$this->delegatedAdmin = \Yii::$app->params['google']['delegatedAdmin'];
$this->spreadsheetId = \Yii::$app->params['google']['spreadsheetId'];

if (!empty($this->jsonAuthFilePath)) {
if (file_exists($this->jsonAuthFilePath)) {
$this->jsonAuthString = \file_get_contents($this->jsonAuthFilePath);
Expand Down
8 changes: 7 additions & 1 deletion application/common/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,13 @@ public static function exportToSheets()
'status' => 'start',
]);

$googleSheetsClient = new Sheets();
$googleSheetsClient = new Sheets([
'applicationName' => Yii::$app->params['google']['applicationName'],
'jsonAuthFilePath' => Yii::$app->params['google']['jsonAuthFilePath'],
'jsonAuthString' => Yii::$app->params['google']['jsonAuthString'],
'delegatedAdmin' => Yii::$app->params['google']['delegatedAdmin'],
'spreadsheetId' => Yii::$app->params['google']['spreadsheetId'],
]);

$activeUsers = User::find()->where(['active' => 'yes'])->all();
$table = [];
Expand Down

0 comments on commit 7cf39d9

Please sign in to comment.