<?php
namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;

class CorrectNumberOfSentencesCommand extends Command
{
    public function initialize()
    {
        parent::initialize();
        $this->loadModel('SentencesLists');
        $this->loadModel('SentencesSentencesLists');
    }

    public function execute(Arguments $args, ConsoleIo $io)
    {
        $query = $this->SentencesSentencesLists->find();
        $query->select([
            'sentences_list_id',
            'count' => $query->func()->count('*')
        ])
        ->group('sentences_list_id');
        foreach ($query as $listAndCount) {
            $sentencesList = $this->SentencesLists->get($listAndCount->sentences_list_id);
            $sentencesList->numberOfSentences = $listAndCount->count;
            $this->SentencesLists->save($sentencesList);
        }
    }
}

Add Command to correct `numberOfSentences` in `sentences_lists` table
Add Command to correct `numberOfSentences` in `sentences_lists` table

This command counts the number of records in the 
`sentences_sentences_lists` table, grouped by `sentences_list_id`, and 
replaces `sentences_lists.numberOfSentences` with this value.
