Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

burzum / cakephp-user-tools / 318

7 Sep 2017 - 14:12 coverage: 37.811% (-0.6%) from 38.365%
318

Pull #46

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Improving the code and doc blocks
Pull Request #46: Updating the plugin to CakePHP 3.4 changes

43 of 114 new or added lines in 7 files covered. (37.72%)

21 existing lines in 4 files now uncovered.

304 of 804 relevant lines covered (37.81%)

2.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0
/src/Shell/UserShell.php
1
<?php
2
/**
3
 * UserShell
4
 *
5
 * @author Florian Krämer
6
 * @copyright 2013 - 2017 Florian Krämer
7
 * @license MIT
8
 */
9
namespace Burzum\UserTools\Shell;
10

11
use Cake\Cache\Cache;
12
use Cake\Console\Shell;
13
use Cake\Datasource\ConnectionManager;
14
use Cake\ORM\TableRegistry;
15

16
class UserShell extends Shell {
17

18
        /**
19
         * Assign $this->connection to the active task if a connection param is set.
20
         *
21
         * @return void
22
         */
23
        public function startup() {
24
                parent::startup();
!
25
                Cache::disable();
!
26
                $this->UserTable = TableRegistry::get($this->param('model'), [
!
27
                        'connection' => ConnectionManager::get($this->param('connection'))
!
28
                ]);
!
29
                if (!$this->UserTable->hasBehavior('Burzum/UserTools.User')) {
!
30
                        $this->UserTable->addBehavior('Burzum/UserTools.User');
!
31
                }
!
32
                try {
!
33
                        $this->UserTable->schema();
!
34
                } catch (\Exception $e) {
!
35
                        $this->err($e->getMessage());
!
36
                        $this->_stop(1);
!
37
                }
!
38
        }
!
39

40
        /**
41
         * Removes expired registrations
42
         *
43
         * @return void
44
         */
45
        public function removeExpired() {
46
                $count = $this->UserTable->removeExpiredRegistrations();
!
47
                $this->out(__dn(
!
48
                        'burzum/user_tools',
!
49
                        'Removed {0,number,integer} expired registration.',
!
50
                        'Removed {0,number,integer} expired registrations.',
!
51
                        $count,
!
52
                        $count
!
53
                ));
!
54
        }
!
55

56
        /**
57
         * Sets a new password for an user.
58
         *
59
         * cake user setPassword <searchTerm> <newPassword> <field | optional>
60
         *
61
         * @return void
62
         */
63
        public function setPassword() {
64
                if (count($this->args) < 2) {
!
NEW
65
                        $this->abort(__d('burzum/user_tools', 'You need to call this command with at least tow arguments.'));
!
66
                }
!
67

68
                $field = 'username';
!
69
                if (count($this->args) >= 3) {
!
70
                        $field = $this->args[2];
!
71
                }
!
72

73
                $user = $this->UserTable->find()->where([$field => $this->args[0]])->first();
!
74
                $user->password = $this->UserTable->hashPassword($this->args[1]);
!
75
                if ($this->UserTable->save($user, ['validate' => false])) {
!
76
                        $this->out('Password saved');
!
77
                }
!
78
        }
!
79

80
        /**
81
         * Gets the option parser instance and configures it.
82
         *
83
         * @return \Cake\Console\ConsoleOptionParser
84
         */
85
        public function getOptionParser() {
86
                $parser = parent::getOptionParser();
!
87

NEW
88
                $parser->setDescription(
!
89
                        'Users utility shell'
!
90
                )
!
91
                ->addOption('model', [
!
92
                        'short' => 'm',
!
93
                        'help' => 'User model to load',
!
94
                        'default' => 'Users'
!
95
                ])
!
96
                ->addOption('connection', [
!
97
                        'short' => 'c',
!
98
                        'help' => 'The connection to use',
!
99
                        'default' => 'default'
!
100
                ])
!
101
                ->addOption('behavior', [
!
102
                        'short' => 'b',
!
103
                        'help' => 'Auto-load the behavior if the model doesn\'t have it loaded.',
!
104
                        'default' => 1
!
105
                ]);
!
106

107
                return $parser;
!
108
        }
!
109
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc