Skip to content

Commit 095eb55

Browse files
committed
maybe this will work. Solving issue with composer compatibility attempt #3.
1 parent 64b984e commit 095eb55

File tree

6 files changed

+105
-35
lines changed

6 files changed

+105
-35
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ With time, this package would contain all modifications of the bare Laravel app.
1616
## Installation
1717

1818
1. Add
19-
`"unrulynatives/helpers": "0.0.10"`
19+
`"unrulynatives/helpers": "0.0.13"`
2020
to your composer.json file.
2121

2222
2. Add this to your `config/app.php` file in packages section

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
},
1414
"autoload": {
1515
"psr-4": {
16+
"App\\": "app/",
1617

17-
18-
"Unrulynatives\\Helpers\\": "src"
18+
"Unrulynatives\\Helpers\\": "src/"
1919

2020
}
2121
},
2222
"minimum-stability": "dev"
2323
}
24+

src/unstarter_controllers/UNStarter/AdminToolsController.php

+45-26
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ public function regenerate_model_name($itemkind='relateds') {
177177
$matchcontent = Input::get('matchcontent');
178178
$newcontent = Input::get('newcontent');
179179

180+
if(!isset($matchcontent)) {
181+
$matchcontent = 'bb';
182+
}
183+
if(!isset($newcontent)) {
184+
$newcontent = 'ccc';
185+
}
186+
187+
180188
$itemtype = str_singular($itemkind);
181189

182190
//getting Class name
@@ -189,53 +197,64 @@ public function regenerate_model_name($itemkind='relateds') {
189197

190198

191199
if (class_exists($name) && get_parent_class($class) == 'Illuminate\Database\Eloquent\Model') {
192-
$model = $class->where('name','')
200+
$model = $class->where($field2change,$matchcontent)
193201
->get();
194202

195203
// the action itself:
196-
$itemstobeactedupon = $class->where('name',$matchcontent)->count();
204+
$itemstobeactedupon = $class->where($field2change,$matchcontent)->count();
197205
// $itemstobeacteduponbefore = \App\Models\Related::where('name','')->count();
198206

199207

200208

201209

202-
$acteduponarray = $class->where('name',$matchcontent)->pluck('id');
210+
$acteduponarray = $class->where($field2change,$matchcontent)
211+
// ->limit(20)
212+
->pluck('id');
203213
$affected = $acteduponarray->count();
204214

205215
// doing the job!
206216
$perform = Input::get('perform');
207-
if(isset($perform) && $perform=1) {
217+
if(isset($perform) && $perform==1) {
208218

209219
// the action itself:
210-
$itemstobeacteduponbefore = $class->where('name',$matchcontent)->count();
220+
$itemstobeacteduponbefore = $class->where($field2change,$matchcontent)->count();
211221
// $actedupon = $class->destroy($acteduponarray);
212-
$objects = $class->whereIn('id', $acteduponarray)->get();
222+
$objects = $class->whereIn('id', $acteduponarray)
223+
// ->limit(20)
224+
->get();
213225

214226

215227
echo "List of items changed: <br>";
216228
foreach($objects as $o) {
217-
$o->name = $newcontent;
218-
$o->save();
219-
echo 'Changed: '.$o->id.'<br>';
220-
221-
222-
// if possible, retrieve page title and use it as event name
223-
$page_url = $o->URL;
224-
try {
225-
226-
// Revel's privete function, now a helper
227-
// $page_title = $this->_get_url_title($page_url);
228-
$page_title = SitewideHelper::parseTitle($page_url);
229-
} catch(ErrorException $e) {
230-
return Redirect::back()->withInput()->withErrors(['error accessing url']);
231-
// TO DO: fix error msg
232-
}
233-
// hot fix for L5.3 BB #952
234-
$page_title2 = substr($page_title,0,150).'...';
235-
236-
237229

238230

231+
// if possible, retrieve page title and use it as event name
232+
$page_url = $o->URL;
233+
try {
234+
235+
// Revel's privete function, now a helper
236+
// $page_title = $this->_get_url_title($page_url);
237+
$page_title = \App\Helpers\SitewideHelper::parseTitle($page_url);
238+
// dd($page_title);
239+
} catch(ErrorException $e) {
240+
return Redirect::back()->withInput()->withErrors(['error accessing url']);
241+
// TO DO: fix error msg
242+
}
243+
// hot fix for L5.3 BB #952
244+
$page_title2 = substr($page_title,0,150).'...';
245+
246+
echo $page_title;
247+
248+
if(isset($page_title2) && $page_title2 !='') {
249+
$o->name = $page_title2;
250+
251+
} else {
252+
$o->name = '';
253+
254+
}
255+
$o->save();
256+
echo 'Changed: '.$o->id.'<br>';
257+
echo $o->URL;
239258

240259
}
241260

src/unstarter_views/admin/dashboard_admintools.blade.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="content un_flex un_flex_vt">
1818
<h3 class="">
19-
Admin Tools Dashboard
19+
Admin Tools Dashboard 2
2020
</h3>
2121

2222
<div class="un_box links">
@@ -33,6 +33,8 @@
3333

3434
<a href="{{URL::to('users')}}" title="powered by spatie/permissions, included in Admin panel in package Amranidev\ScaffoldInterface">assign_roles</a>
3535

36+
<a href="{{URL::to('unstarter/admintools/regenerate-model-name')}}" title="powered by fabpot/goutte, included in Admin panel in package Amranidev\ScaffoldInterface">regenerate-model-name</a>
37+
3638

3739
</div>
3840

src/unstarter_views/admin/tools/_info_on_perform.blade.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
@if(!isset($perform))
55
<div class="communique-danger communique-cleared" id="">
6-
<h4>Czy wiesz, co robisz?!</h4>
7-
<p>Uruchomienie narzędzia wykonuje się przez dodanie <code>?perform=1</code> do URL. Kliknij na poniższy guzik:
6+
<h4>Are you sure you know what you are doing?!</h4>
7+
<p>You can trigger this admin tool by adding extra parameter to URL: <code>?perform=1</code>. Just click this button:
88

99
<a href="{{ URL::to(Request::url().'?perform=1') }}" class="btn btn-danger" target="_blank">
1010
<i class="fa fa-start"></i>
@@ -14,9 +14,9 @@
1414
</div>
1515
@elseif(isset($perform) && $perform == 1)
1616

17-
<div class="communique-info communique-cleared" id="">
18-
<h4>Odpaliło się! </h4>
19-
<p>Powinieneś widzieć rezultat!</p>
17+
<div class="communique-danger communique-cleared" id="">
18+
<h4>It worked!</h4>
19+
<p>You should be able to see the results!</p>
2020

2121
itemstobeacteduponbefore: {{@$itemstobeacteduponbefore}}
2222
Affected: {{$affected}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@extends('unstarter.layouts.master_bootstrap_simple')
2+
3+
@section('content')
4+
5+
6+
@include('unstarter.admin.tools._admintools')
7+
@include('unstarter.admin.tools._info_on_perform')
8+
9+
10+
<div class="un_title">
11+
<h2>This tool fills the field `{{$field2change}}` if it is empty! </h2>
12+
13+
<p>When needed? When lots of instances of a model has the name empty.</p>
14+
</div>
15+
16+
17+
18+
@if(!isset($class))
19+
<div class="communique-info communique-cleared" id="">
20+
<h4>No model selected!</h4>
21+
<p>The URL should contain your model name, lowercase, plural (e. `features` for model `Feature`)</p>
22+
23+
24+
25+
</div>
26+
@else
27+
<div class="csch_dark2">
28+
<h3 class="un_title">Items matching criteria: {{@$model->count() }}.</h3>
29+
30+
@if(isset($perform) && $perform == 1)
31+
Instances to be affected: <strong title="itemstobeacteduponbefore">{{ @$itemstobeacteduponbefore}}</strong> |
32+
Array acted upon: <strong title="acteduponarray">{{$acteduponarray}}</strong>
33+
@endif
34+
35+
<h2>
36+
$field2change = {{$field2change}} |
37+
$matchcontent = {{$matchcontent}} |
38+
$newcontent = {{$newcontent}}
39+
</h2>
40+
</div>
41+
@endif
42+
43+
44+
45+
46+
47+
@stop
48+

0 commit comments

Comments
 (0)