Skip to content

Commit 920708f

Browse files
committed
Merge branch 'features/license-import'
2 parents 85a64f9 + 4b59a6c commit 920708f

File tree

517 files changed

+13357
-3940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

517 files changed

+13357
-3940
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ composer.phar
77
/app/database/*.sqlite
88
/app/storage/meta/services.json
99
/app/config/*/mail.php
10+
/app/config/*/session.php
1011
/app/config/*/database.php
1112
/app/config/*/app.php
1213
public/packages/*
@@ -24,3 +25,5 @@ public/uploads/logo.png
2425
public/assets/.siteflow
2526
app/config/local/session.php
2627
.couscous
28+
tests/_support/_generated/*
29+
tests/_data/scenarios

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
addons:
2-
hosts:
3-
- AlisonMBP
2+
hosts:
3+
- snipe-it.dev
4+
sudo: false
45

56
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints
67
language: php
@@ -17,7 +18,7 @@ env:
1718

1819
# execute any number of scripts before the test run, custom env's are available as variables
1920
before_script:
20-
- if [[ "$DB" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS snipeit_laravel;" -utravis; fi
21+
- if [[ "$DB" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS snipeit_unit;" -utravis; fi
2122
- curl -s http://getcomposer.org/installer | php
2223
- cp app/config/testing/app.example.php app/config/testing/app.php
2324
- cp app/config/testing/database.example.php app/config/testing/database.php
@@ -32,9 +33,17 @@ before_script:
3233

3334
# omitting "script:" will default to phpunit
3435
# use the $DB env variable to determine the phpunit.xml to use
36+
# script: ./vendor/bin/codecept run
3537
script: phpunit
3638

3739
# configure notifications (email, IRC, campfire etc)
3840
notifications:
41+
email: false
3942
slack:
4043
secure: vv9we1RxB9RsrMbomSdq6D7vz/okobw87pEkgIZjB+hj1QpQ2by90gsPsOa+NgsJEFaEP7e4KlT6SH8kK+zhbmuKaUd3d1//XdcancE22LZXi6tkiB5yuR/Jhhb1LLDqyGJTB4D92hMnnCPiUjpxNA3r437ttNeYRdYIEEP3drA=
44+
webhooks:
45+
urls:
46+
- https://webhooks.gitter.im/e/5e136eb0c1965f3918d0
47+
on_success: change # options: [always|never|change] default: always
48+
on_failure: change # options: [always|never|change] default: always
49+
on_start: false # default: false

CHANGELOG.md

Lines changed: 886 additions & 325 deletions
Large diffs are not rendered by default.

app/commands/AppCommand.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AppCommand extends Command
1818
*
1919
* @var string
2020
*/
21-
protected $description = '';
21+
protected $description = 'This command kicks off your database table creation and migration, and creates your first admin user.';
2222

2323
/**
2424
* Holds the user information.
@@ -28,7 +28,7 @@ class AppCommand extends Command
2828
protected $userData = array(
2929
'first_name' => null,
3030
'last_name' => null,
31-
'email' => null,
31+
'username' => null,
3232
'password' => null
3333
);
3434

@@ -66,6 +66,7 @@ public function fire()
6666
// Let's ask the user some questions, shall we?
6767
$this->askUserFirstName();
6868
$this->askUserLastName();
69+
$this->askUserUsername();
6970
$this->askUserEmail();
7071
$this->askUserPassword();
7172

@@ -89,10 +90,10 @@ public function fire()
8990
$this->call('migrate:install');
9091

9192
// Run the Sentry Migrations
92-
$this->call('migrate', array('--package' => 'cartalyst/sentry'));
93+
$this->call('migrate', array('--package' => 'cartalyst/sentry','--force'=>true));
9394

9495
// Run the Migrations
95-
$this->call('migrate');
96+
$this->call('migrate', array('--force'=>true));
9697

9798
// Create the default user and default groups.
9899
$this->sentryRunner();
@@ -162,7 +163,7 @@ protected function askUserLastName()
162163
}
163164

164165
/**
165-
* Asks the user for the user email address.
166+
* Asks the user for the username address.
166167
*
167168
* @return void
168169
* @todo Use the Laravel Validator
@@ -171,7 +172,7 @@ protected function askUserEmail()
171172
{
172173
do {
173174
// Ask the user to input the email address
174-
$email = $this->ask('Please enter your user email: ');
175+
$email = $this->ask('Please enter your email: ');
175176

176177
// Check if email is valid
177178
if ($email == '') {
@@ -185,6 +186,32 @@ protected function askUserEmail()
185186
while ( ! $email);
186187
}
187188

189+
190+
/**
191+
* Asks the user for the username address.
192+
*
193+
* @return void
194+
* @todo Use the Laravel Validator
195+
*/
196+
protected function askUserUsername()
197+
{
198+
do {
199+
// Ask the user to input the username
200+
$username = $this->ask('Please enter your username: ');
201+
202+
// Check if username is valid
203+
if ($username == '') {
204+
// Return an error message
205+
$this->error('Username is invalid. Please try again.');
206+
}
207+
208+
// Store the username address
209+
$this->userData['username'] = $username;
210+
}
211+
while ( ! $username);
212+
}
213+
214+
188215
/**
189216
* Asks the user for the user password.
190217
*
@@ -197,7 +224,7 @@ protected function askUserPassword()
197224
// Ask the user to input the user password
198225
$password = $this->ask('Please enter your user password (at least 8 characters): ');
199226

200-
// Check if email is valid
227+
// Check if password is valid
201228
if ($password == '') {
202229
// Return an error message
203230
$this->error('Password is invalid. Please try again.');
@@ -217,9 +244,9 @@ protected function askUserPassword()
217244
protected function askUserDummyData()
218245
{
219246
// Ask the user to input the user password
220-
$dummydata = $this->ask('Do you want to seed your database with dummy data? y/n (default is yes): ');
247+
$dummydata = $this->ask('Do you want to seed your database with dummy data? Y/n (default is yes): ');
221248

222-
$this->dummyData = ( strstr($dummydata, 'y' ) || empty($dummydata) ) ? true : false;
249+
$this->dummyData = ( strstr($dummydata, 'Y' ) || empty($dummydata) ) ? true : false;
223250
}
224251

225252
/**
@@ -329,7 +356,7 @@ protected function sentryCreateUser()
329356
$user = Sentry::getUserProvider()->create($data);
330357

331358
// Associate the Admin group to this user
332-
$group = Sentry::getGroupProvider()->findById(1);
359+
$group = Sentry::findGroupByName('Admin');
333360
$user->addGroup($group);
334361

335362
// Show the success message
@@ -350,6 +377,7 @@ protected function sentryCreateDummyUser()
350377
'first_name' => 'John',
351378
'last_name' => 'Doe',
352379
'email' => '[email protected]',
380+
'username' => '[email protected]',
353381
'password' => substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,10))),1,10),
354382
'notes' => 'Generated on install',
355383
'activated' => 1,

app/commands/ImportCommand.php renamed to app/commands/AssetImportCommand.php

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
use Symfony\Component\Console\Input\InputArgument;
66
use League\Csv\Reader;
77

8-
class ImportCommand extends Command {
8+
class AssetImportCommand extends Command {
99

1010
/**
1111
* The console command name.
1212
*
1313
* @var string
1414
*/
15-
protected $name = 'import:csv';
15+
protected $name = 'asset-import:csv';
1616

1717
/**
1818
* The console command description.
1919
*
2020
* @var string
2121
*/
22-
protected $description = 'Import from CSV';
22+
protected $description = 'Import Assets from CSV';
2323

2424
/**
2525
* Create a new command instance.
@@ -42,9 +42,9 @@ public function fire()
4242

4343

4444
if (!$this->option('testrun')=='true') {
45-
$this->comment('======= Importing '.$filename.' =========');
45+
$this->comment('======= Importing Assets from '.$filename.' =========');
4646
} else {
47-
$this->comment('====== TEST ONLY Import for '.$filename.' ====');
47+
$this->comment('====== TEST ONLY Asset Import for '.$filename.' ====');
4848
$this->comment('============== NO DATA WILL BE WRITTEN ==============');
4949
}
5050

@@ -63,66 +63,77 @@ public function fire()
6363

6464
// Let's just map some of these entries to more user friendly words
6565

66+
// User's name
6667
if (array_key_exists('0',$row)) {
67-
$user_name = $row[0];
68+
$user_name = trim($row[0]);
6869
} else {
6970
$user_name = '';
7071
}
7172

73+
// User's email
7274
if (array_key_exists('1',$row)) {
73-
$user_email = $row[1];
75+
$user_email = trim($row[1]);
7476
} else {
7577
$user_email = '';
7678
}
7779

80+
// Asset Category
7881
if (array_key_exists('2',$row)) {
79-
$user_asset_category = $row[2];
82+
$user_asset_category = trim($row[2]);
8083
} else {
8184
$user_asset_category = '';
8285
}
8386

87+
// Asset Name
8488
if (array_key_exists('3',$row)) {
85-
$user_asset_name = $row[3];
89+
$user_asset_name = trim($row[3]);
8690
} else {
8791
$user_asset_name = '';
8892
}
8993

94+
// Asset Manufacturer
9095
if (array_key_exists('4',$row)) {
91-
$user_asset_mfgr = $row[4];
96+
$user_asset_mfgr = trim($row[4]);
9297
} else {
9398
$user_asset_mfgr = '';
9499
}
95100

101+
// Asset model number
96102
if (array_key_exists('5',$row)) {
97-
$user_asset_modelno = $row[5];
103+
$user_asset_modelno = trim($row[5]);
98104
} else {
99105
$user_asset_modelno = '';
100106
}
101107

108+
// Asset serial number
102109
if (array_key_exists('6',$row)) {
103-
$user_asset_serial = $row[6];
110+
$user_asset_serial = trim($row[6]);
104111
} else {
105112
$user_asset_serial = '';
106113
}
107114

115+
// Asset tag
108116
if (array_key_exists('7',$row)) {
109-
$user_asset_tag = $row[7];
117+
$user_asset_tag = trim($row[7]);
110118
} else {
111119
$user_asset_tag = '';
112120
}
113121

122+
// Asset location
114123
if (array_key_exists('8',$row)) {
115-
$user_asset_location = $row[8];
124+
$user_asset_location = trim($row[8]);
116125
} else {
117126
$user_asset_location = '';
118127
}
119128

129+
// Asset notes
120130
if (array_key_exists('9',$row)) {
121-
$user_asset_notes = $row[9];
131+
$user_asset_notes = trim($row[9]);
122132
} else {
123133
$user_asset_notes = '';
124134
}
125135

136+
// Asset purchase date
126137
if (array_key_exists('10',$row)) {
127138
if ($row[10]!='') {
128139
$user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[10]));
@@ -136,17 +147,21 @@ public function fire()
136147
// A number was given instead of a name
137148
if (is_numeric($user_name)) {
138149
$this->comment('User '.$user_name.' is not a name - assume this user already exists');
139-
// No name was given
150+
$user_username = '';
140151

152+
// No name was given
141153
} elseif ($user_name=='') {
142154
$this->comment('No user data provided - skipping user creation, just adding asset');
143155
$first_name = '';
144156
$last_name = '';
157+
$user_username = '';
158+
145159
} else {
146160

147161
$name = explode(" ", $user_name);
148162
$first_name = $name[0];
149163
$email_last_name = '';
164+
$email_prefix = $first_name;
150165

151166
if (!array_key_exists(1, $name)) {
152167
$last_name='';
@@ -171,6 +186,9 @@ public function fire()
171186

172187
}
173188

189+
190+
$user_username = $email_prefix;
191+
174192
// Generate an email based on their name if no email address is given
175193
if ($user_email=='') {
176194
if ($first_name=='Unknown') {
@@ -179,14 +197,12 @@ public function fire()
179197
$email = strtolower($email_prefix).'@'.$this->option('domain');
180198
$user_email = str_replace("'",'',$email);
181199
}
182-
183-
184-
185200
}
186201

187202
$this->comment('Full Name: '.$user_name);
188203
$this->comment('First Name: '.$first_name);
189204
$this->comment('Last Name: '.$last_name);
205+
$this->comment('Username: '.$user_username);
190206
$this->comment('Email: '.$user_email);
191207
$this->comment('Category Name: '.$user_asset_category);
192208
$this->comment('Item: '.$user_asset_name);
@@ -200,22 +216,23 @@ public function fire()
200216

201217
$this->comment('------------- Action Summary ----------------');
202218

203-
if ($user_email!='') {
204-
if ($user = User::where('email', $user_email)->first()) {
205-
$this->comment('User '.$user_email.' already exists');
219+
if ($user_username!='') {
220+
if ($user = User::where('username', $user_username)->whereNotNull('username')->first()) {
221+
$this->comment('User '.$user_username.' already exists');
206222
} else {
207223
// Create the user
208224
$user = Sentry::createUser(array(
209225
'first_name' => $first_name,
210226
'last_name' => $last_name,
211227
'email' => $user_email,
228+
'username' => $user_username,
212229
'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10),
213230
'activated' => true,
214231
'permissions' => array(
215232
'admin' => 0,
216233
'user' => 1,
217234
),
218-
'notes' => 'Imported user'
235+
'notes' => 'User imported through asset importer'
219236
));
220237

221238
// Find the group using the group id
@@ -311,6 +328,11 @@ public function fire()
311328

312329
$asset = new Asset();
313330
$asset->name = e($user_asset_name);
331+
if ($user_asset_purchase_date!='') {
332+
$asset->purchase_date = $user_asset_purchase_date;
333+
} else {
334+
$asset->purchase_date = NULL;
335+
}
314336
$asset->serial = e($user_asset_serial);
315337
$asset->asset_tag = e($user_asset_tag);
316338
$asset->model_id = $asset_model->id;

0 commit comments

Comments
 (0)