I'm moving a project from laravel to phalcon, code is almost the same, and one of the actions is parsing data from file and add content to database. File has 1883 records (relatively small for my project) but whatever I do there are only 18 records add to db. Here is the code of action that is doing all job:
public function upgradeAction()
{
$this->view->disable();
$lastLon = $lastLat = $lastPrefix = $lastCq = $lastItu = $lastContinent = $lastTz = $lastMask = '';
if ($this->request->isPost()) {
if ($this->request->isAjax()) {
$filePath = 'uploads/pfx/'.$this->request->getPost('fileName');
if (file_exists($filePath)) {
if (Prefixes::count()) {
Prefixes::find()->delete();
}
$prefixHelper = new PrefixHelper();
if ($content = (new PHPhelper())->splitFile($filePath)) {
foreach ($content as $row) {
$p = new Prefixes();
$p->InternalUse = $prefixHelper->removeLeading($row[0]);
$p->lon = $lastLon = ($row[1] != '') ? $prefixHelper->toCoords($row[1]) : $lastLon;
$p->lat = $lastLat = ($row[2] != '') ? $prefixHelper->toCoords($row[2]) : $lastLat;
$p->territory = ($row[3]) ? : '';
$p->prefix = $lastPrefix = ($row[4] != '') ? $prefixHelper->maskToPattern($row[4]) : $lastPrefix;
$p->cq = $lastCq = ($row[5] != '') ? $row[5] : $lastCq;
$p->itu = $lastItu = ($row[6] != '') ? $row[6] : $lastItu;
$p->continent = $lastContinent = ($row[7] != '') ? $row[7] : $lastContinent;
$p->tz = $lastTz = ($row[8] != '') ? $row[8] : $lastTz;
$p->adif = ($row[9]) ? : '';
$p->province = ($row[10]) ? : '';
$p->mask = $lastMask = ($row[13] != '') ? $prefixHelper->maskToPattern($row[13]) : $lastMask;
$success[] = $p->save();
}
}
}
}
}
var_dump($success);
}
I don't see much of a difference between records that are add from those left behind. Besides, everything is copied from the same controller in laravel where it works flowlessly. I can add more code upon request. Please help!