<?php
defined('BASEPATH') or exit('No direct script access allowed');

/**
 * Base class every seeder should extend.
 * Provides access to CI DB and standard `run()` contract.
 */
abstract class BaseSeeder
{
    protected $db;
    protected $CI;

    public function __construct()
    {
        $this->CI = &get_instance();
        $this->db = $this->CI->db;
    }

    /**
     * Log a line to the output buffer.
     */
    protected function log($msg)
    {
        echo "  $msg\n";
    }

    /**
     * Skip a step if a row already exists.
     */
    protected function exists($table, $where)
    {
        return (bool) $this->db->where($where)->count_all_results(db_prefix() . $table);
    }

    /**
     * Every seeder implements this.
     */
    abstract public function run();
}
