/** * Check if a DataObject or DataExtension subclass is allowed by checking if the file * is in the $allowed_modules array * The permission is checked by matching the filePath and modulePath * * @param $className * * @return bool */ public function classNameIsAllowed($className) { if ($this->classNameIsSupported($className)) { $classInfo = new AnnotateClassInfo($className); $filePath = $classInfo->getClassFilePath(); $allowedModules = (array) Config::inst()->get('DataObjectAnnotator', 'enabled_modules'); foreach ($allowedModules as $moduleName) { $modulePath = BASE_PATH . DIRECTORY_SEPARATOR . $moduleName; if (0 === strpos($filePath, $modulePath)) { return true; } } } return false; }
/** * @param string $className */ protected function writeFileContent($className) { $classInfo = new AnnotateClassInfo($className); $filePath = $classInfo->getClassFilePath(); if (!is_writable($filePath)) { DB::alteration_message($className . ' is not writable by ' . get_current_user(), 'error'); } else { $original = file_get_contents($filePath); $generated = $this->getGeneratedFileContent($original, $className); // we have a change, so write the new file if ($generated && $generated !== $original) { file_put_contents($filePath, $generated); DB::alteration_message($className . ' Annotated', 'created'); } else { DB::alteration_message($className); } } }