<commit_before><?php

namespace Rogue\Http\Controllers\Legacy\Web;

use Rogue\Models\Action;
use Illuminate\Http\Request;
use Rogue\Http\Controllers\Controller;

class ActionsController extends Controller
{
    /**
     * Create a controller instance.
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('role:admin,staff', ['only' => ['create', 'store', 'edit', 'update', 'destroy']]);
    }

    /**
     * Create a new action.
     */
    public function create($campaignId)
    {
        $postTypes = [
            'text',
            'photo',
            'voter-reg',
            'share-social',
            'phone-call',
        ];

        return view('actions.create')->with([
            'postTypes' => $postTypes,
            'campaignId' => (int) $campaignId,
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|string',
            'campaign_id' => 'required|integer|exists:campaigns,id',
            'post_type' => 'required|string|in:photo,voter-reg,text,share-social,phone-call',
            'callpower_campaign_id' => 'required_if:post_type,phone-call|exists:actions,callpower_campaign_id',
            'noun' => 'required|string',
            'verb' => 'required|string',
        ]);

        // Checkbox values are only sent from the front end if they are checked.
        // Get checkbox values if sent from the front end or via the API.
        $request['reportback'] = isset($request['reportback']) && $request['reportback'] ? true : false;
        $request['civic_action'] = isset($request['civic_action']) && $request['civic_action'] ? true : false;
        $request['scholarship_entry'] = isset($request['scholarship_entry']) && $request['scholarship_entry'] ? true : false;
        $request['anonymous'] = isset($request['anonymous']) && $request['anonymous'] ? true : false;

        // Check to see if the action exists before creating one.
        $action = Action::where([
            'name' => $request['name'],
            'campaign_id' => $request['campaign_id'],
            'post_type' => $request['post_type'],
        ])->first();

        if (! $action) {
            $action = Action::create($request->all());

            // Log that a action was created.
            info('action_created', ['id' => $action->id]);
        }

        return redirect()->route('campaign-ids.show', $request['campaign_id']);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Rogue\Models\Action  $action
     */
    public function update(Request $request, Action $action)
    {
        $this->validate($request, [
            'name' => 'string',
            'post_type' => 'string',
            'callpower_campaign_id' => 'integer',
            'reportback' => 'boolean',
            'civic_action' => 'boolean',
            'scholarship_entry' => 'boolean',
            'anonymous' => 'boolean',
            'noun' => 'string',
            'verb' => 'string',
        ]);

        $action->update($request->all());

        // Log that an action was updated.
        info('action_updated', ['id' => $action->id]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \Rogue\Models\Action  $campaign
     */
    public function destroy(Action $action)
    {
        $action->delete();

        // Log that an action was deleted.
        info('action_deleted', ['id' => $action->id]);
    }
}
<commit_msg>updates update validaiton rules<commit_after><?php

namespace Rogue\Http\Controllers\Legacy\Web;

use Rogue\Models\Action;
use Illuminate\Http\Request;
use Rogue\Http\Controllers\Controller;

class ActionsController extends Controller
{
    /**
     * Create a controller instance.
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('role:admin,staff', ['only' => ['create', 'store', 'edit', 'update', 'destroy']]);
    }

    /**
     * Create a new action.
     */
    public function create($campaignId)
    {
        $postTypes = [
            'text',
            'photo',
            'voter-reg',
            'share-social',
            'phone-call',
        ];

        return view('actions.create')->with([
            'postTypes' => $postTypes,
            'campaignId' => (int) $campaignId,
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|string',
            'campaign_id' => 'required|integer|exists:campaigns,id',
            'post_type' => 'required|string|in:photo,voter-reg,text,share-social,phone-call',
            'callpower_campaign_id' => 'required_if:post_type,phone-call|exists:actions,callpower_campaign_id',
            'noun' => 'required|string',
            'verb' => 'required|string',
        ]);

        // Checkbox values are only sent from the front end if they are checked.
        // Get checkbox values if sent from the front end or via the API.
        $request['reportback'] = isset($request['reportback']) && $request['reportback'] ? true : false;
        $request['civic_action'] = isset($request['civic_action']) && $request['civic_action'] ? true : false;
        $request['scholarship_entry'] = isset($request['scholarship_entry']) && $request['scholarship_entry'] ? true : false;
        $request['anonymous'] = isset($request['anonymous']) && $request['anonymous'] ? true : false;

        // Check to see if the action exists before creating one.
        $action = Action::where([
            'name' => $request['name'],
            'campaign_id' => $request['campaign_id'],
            'post_type' => $request['post_type'],
        ])->first();

        if (! $action) {
            $action = Action::create($request->all());

            // Log that a action was created.
            info('action_created', ['id' => $action->id]);
        }

        return redirect()->route('campaign-ids.show', $request['campaign_id']);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Rogue\Models\Action  $action
     */
    public function update(Request $request, Action $action)
    {
        $this->validate($request, [
            'name' => 'string',
            'post_type' => 'string|in:photo,voter-reg,text,share-social,phone-call',
            'callpower_campaign_id' => 'required_if:post_type,phone-call|exists:actions,callpower_campaign_id',
            'reportback' => 'boolean',
            'civic_action' => 'boolean',
            'scholarship_entry' => 'boolean',
            'anonymous' => 'boolean',
            'noun' => 'string',
            'verb' => 'string',
        ]);

        $action->update($request->all());

        // Log that an action was updated.
        info('action_updated', ['id' => $action->id]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \Rogue\Models\Action  $campaign
     */
    public function destroy(Action $action)
    {
        $action->delete();

        // Log that an action was deleted.
        info('action_deleted', ['id' => $action->id]);
    }
}

{'fraction_non_alphanumeric': 0.16035487288135594, 'fraction_numerical': 0.0, 'mean_word_length': 2.2782118055555554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672087', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2164, 'n_words': 455}