4 * Create DAO ORM classes.
6 class CRM_Core_CodeGen_DAO
extends CRM_Core_CodeGen_BaseTask
{
18 public function __construct($config, $name) {
19 parent
::__construct($config);
25 * TRUE if an update is needed.
27 public function needsUpdate() {
28 if (!file_exists($this->getAbsFileName())) {
31 return $this->getChecksum() !== self
::extractChecksum($this->getAbsFileName(), ';\(GenCodeChecksum:([a-z0-9]+)\);');
34 public function run() {
35 echo "Generating {$this->name} as " . $this->getRelFileName() . "\n";
37 if (empty($this->tables
[$this->name
]['base'])) {
38 echo "No base defined for {$this->name}, skipping output generation\n";
42 $template = new CRM_Core_CodeGen_Util_Template('php');
43 $template->assign('table', $this->tables
[$this->name
]);
44 $template->assign('genCodeChecksum', $this->getChecksum());
45 $template->run('dao.tpl', $this->getAbsFileName());
48 public function getRelFileName() {
49 return $this->tables
[$this->name
]['fileName'];
55 public function getAbsFileName() {
56 $directory = $this->config
->phpCodePath
. $this->tables
[$this->name
]['base'];
57 CRM_Core_CodeGen_Util_File
::createDir($directory);
58 $absFileName = $directory . $this->getRelFileName();
62 protected static function extractChecksum($file, $regex) {
63 $content = file_get_contents($file);
64 if (preg_match($regex, $content, $matches)) {
72 protected function getChecksum() {
73 if (!$this->checksum
) {
74 CRM_Utils_Array
::flatten($this->tables
[$this->name
], $flat);
76 $this->checksum
= md5($this->config
->getSourceDigest() . json_encode($flat));
78 return $this->checksum
;