3.12.0-b1.php
5 years ago
3.12.0-b7.php
5 years ago
4.0.0-b1.php
4 years ago
4.0.0-b3.php
4 years ago
4.0.0-rc3.php
4 years ago
4.0.0-rc4.php
4 years ago
4.0.1-b1.php
4 years ago
4.0.4-b1.php
4 years ago
4.1.2-b1.php
5 years ago
4.1.2-b2.php
4 years ago
4.10.0-b1.php
3 years ago
4.11.0-b1.php
3 years ago
4.11.0-rc2.php
3 years ago
4.12.0-b1.php
3 years ago
4.12.0-b2.php
3 years ago
4.12.0-b3.php
3 years ago
4.12.0-b4.php
3 years ago
4.3.0-b3.php
4 years ago
4.3.0-b4.php
4 years ago
4.3.0-rc2.php
4 years ago
4.4.0-b1.php
4 years ago
4.5.0-b1.php
4 years ago
4.6.0-b1.php
4 years ago
4.6.0-b4.php
4 years ago
4.6.2-rc2.php
4 years ago
4.7.0-b2.php
4 years ago
4.7.1-b1.php
4 years ago
5.0.0-b1.php
4 years ago
4.11.0-rc2.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | namespace Piwik\Updates; |
| 12 | |
| 13 | use Piwik\Common; |
| 14 | use Piwik\Container\StaticContainer; |
| 15 | use Piwik\Db; |
| 16 | use Piwik\Piwik; |
| 17 | use Piwik\Plugins\UsersManager\Emails\UserInviteEmail; |
| 18 | use Piwik\Plugins\UsersManager\Model; |
| 19 | use Piwik\Site; |
| 20 | use Piwik\Updater; |
| 21 | use Piwik\Updater\Migration; |
| 22 | use Piwik\Updater\Migration\Factory as MigrationFactory; |
| 23 | use Piwik\Updates as PiwikUpdates; |
| 24 | |
| 25 | /** |
| 26 | * Update for version 4.11.0-rc2 |
| 27 | */ |
| 28 | class Updates_4_11_0_rc2 extends PiwikUpdates |
| 29 | { |
| 30 | /** |
| 31 | * @var MigrationFactory |
| 32 | */ |
| 33 | private $migration; |
| 34 | |
| 35 | private $pendingUsers; |
| 36 | |
| 37 | private $userTable; |
| 38 | |
| 39 | public function __construct(MigrationFactory $factory) |
| 40 | { |
| 41 | $this->migration = $factory; |
| 42 | $this->userTable = Common::prefixTable('user'); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param Updater $updater |
| 47 | * |
| 48 | * @return Migration[] |
| 49 | */ |
| 50 | public function getMigrations(Updater $updater) |
| 51 | { |
| 52 | try { |
| 53 | $this->pendingUsers = Db::fetchAll( |
| 54 | "SELECT * FROM $this->userTable WHERE invite_status = ? ", |
| 55 | ['pending'] |
| 56 | ); |
| 57 | } catch (\Exception $e) { |
| 58 | // ignore any errors. The column might not exist when updating from an older version, |
| 59 | // so there wouldn't be anything to update anyway |
| 60 | } |
| 61 | return [ |
| 62 | $this->migration->db->dropColumn('user', 'invite_status'), |
| 63 | $this->migration->db->addColumns('user', ['invite_token' => 'VARCHAR(191) DEFAULT null']), |
| 64 | $this->migration->db->addColumns('user', ['invited_by' => 'VARCHAR(100) DEFAULT null']), |
| 65 | $this->migration->db->addColumns('user', ['invite_expired_at' => 'TIMESTAMP null DEFAULT null']), |
| 66 | $this->migration->db->addColumns('user', ['invite_accept_at' => 'TIMESTAMP null DEFAULT null']), |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | public function doUpdate(Updater $updater) |
| 71 | { |
| 72 | $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); |
| 73 | |
| 74 | $model = new Model(); |
| 75 | if (!empty($this->pendingUsers)) { |
| 76 | foreach ($this->pendingUsers as $user) { |
| 77 | $model->deleteAllTokensForUser($user['login']); |
| 78 | |
| 79 | $site = $model->getSitesAccessFromUser($user['login']); |
| 80 | if (isset($site[0])) { |
| 81 | $site = new Site($site[0]['site']); |
| 82 | $siteName = $site->getName(); |
| 83 | } else { |
| 84 | $siteName = "Default Site"; |
| 85 | } |
| 86 | //generate Token |
| 87 | $generatedToken = $model->generateRandomTokenAuth(); |
| 88 | |
| 89 | //attach token to user |
| 90 | $model->attachInviteToken($user['login'], $generatedToken, 7); |
| 91 | |
| 92 | // send email |
| 93 | $email = StaticContainer::getContainer()->make(UserInviteEmail::class, [ |
| 94 | 'currentUser' => Piwik::getCurrentUserLogin(), |
| 95 | 'invitedUser' => $user, |
| 96 | 'siteName' => $siteName, |
| 97 | 'token' => $generatedToken, |
| 98 | 'expiryInDays' => 7 |
| 99 | ]); |
| 100 | $email->safeSend(); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 |