예제 #1
0
파일: unit.php 프로젝트: ssrsfs/blg
 public function setUp()
 {
     // Mock source for news articles
     Mock::generate('Dbi_Source');
     $model = new Model_News_Article();
     $mock = new MockDbi_Source();
     $mock->returns('select', new Dbi_Recordset_Array($model, array(array('newsid' => 1, 'title' => 'Article One', 'article' => '<p>Body 1</p>', 'summary' => 'Summary 1'), array('newsid' => 2, 'title' => 'Article Two', 'article' => '<p>Body 2</p>', 'summary' => 'Summary 2'))));
     $this->_oldSource = Dbi_Source::GetModelSource($model);
     Dbi_Source::SetModelSource($model, $mock);
 }
예제 #2
0
파일: dbexport.inc.php 프로젝트: ssrsfs/blg
$args = array_slice($argv, 2);
if (count($args)) {
    $classes = array();
    foreach ($args as $cls) {
        if (class_exists($cls) && is_subclass_of($cls, 'Dbi_Schema')) {
            $classes[] = $cls;
        } else {
            die("ERROR: The {$cls} does not exist or is not a schema/model class.\n");
        }
    }
} else {
    $files = scandir(TYPEF_SOURCE_DIR . '/classes/BaseModel');
    if (substr($file, 0, 1) != '.') {
        foreach ($files as $file) {
            if (pathinfo($file, PATHINFO_EXTENSION) == 'php') {
                $cls = 'BaseModel_' . pathinfo($file, PATHINFO_FILENAME);
                if (class_exists($cls) && is_subclass_of($cls, 'Dbi_Schema')) {
                    $classes[] = $cls;
                } else {
                    die("ERROR: The {$cls} does not exist or is not a schema/model class.\n");
                }
            }
        }
    }
}
foreach ($classes as $cls) {
    echo "Exporting {$cls}...\n";
    $mod = new $cls();
    $src = Dbi_Source::GetModelSource($mod);
    $src->configureSchema($mod);
}
예제 #3
0
파일: Record.php 프로젝트: ssrsfs/blg
 /**
  * Delete the record.
  */
 public function delete()
 {
     // TODO: Should we check to see if the record is dirty first?
     if (!$this->exists()) {
         return;
     }
     $this->_model->notify(Dbi_Model::EVENT_BEFOREDELETE, $this);
     $cls = get_class($this->_model);
     $clone = new $cls();
     $primary = $clone->index('primary');
     if (is_null($primary)) {
         throw new Exception("Model does not have a primary key");
     }
     foreach ($primary['fields'] as $key) {
         $clone->where("{$key} = ?", $this->_data[$key]);
     }
     Dbi_Source::GetModelSource($this->_model)->delete($clone);
     $this->_exists = false;
     $this->_valid = false;
 }
예제 #4
0
파일: Install.php 프로젝트: ssrsfs/blg
 /**
  * Install a package from the local directory.
  * @param string $tarball The path to the package file.
  * @param array|bool $force An array of files that should be overwritten even if the local copy is customized,
  * or TRUE if they should always be overwritten, or FALSE if they should never be overwritten.
  * @param bool $getDependencies If true, look for dependency updates on the provider.
  * @return array|boolean An array of strings describing the installation or false if the installation failed.
  */
 public static function Package($tarball, $force = array(), $getDependencies = false)
 {
     $result = array();
     if (!file_exists($tarball)) {
         throw new Exception("File {$tarball} does not exist");
     }
     $dir = tempnam(sys_get_temp_dir(), 'TYPEF_');
     unlink($dir);
     mkdir($dir);
     exec('tar --directory=' . $dir . ' -zxf ' . $tarball);
     $package = '';
     // Download dependencies if a provider is available
     if (TYPEF_PROVIDER && $getDependencies) {
         if (file_exists("{$dir}/source/packages")) {
             $packages = scandir("{$dir}/source/packages");
             $dependencies = array();
             foreach ($packages as $package) {
                 if (substr($package, 0, 1) != '.') {
                     $pathinfo = pathinfo($package);
                     if ($pathinfo['extension'] == 'xml') {
                         $dependencies[] = $pathinfo['filename'];
                         self::_GetDependencies($dir, $pathinfo['filename'], $dependencies);
                     }
                 }
             }
         }
     }
     $ftp = new Typeframe_File();
     $packed = scandir("{$dir}/source/packages");
     foreach ($packed as $pf) {
         $pathinfo = pathinfo($pf);
         if ($pathinfo['extension'] == 'xml') {
             $package = $pathinfo['filename'];
             self::_CopyFiles($ftp, $dir, '', $package, $force);
             // Always copy the package file
             $ftp->copy("{$dir}/source/packages/{$pf}", '/source/packages/' . $pf);
         }
     }
     // Make writeable directories
     $packageFiles = array();
     if (file_exists("{$dir}/source/packages")) {
         $packageFiles = scandir("{$dir}/source/packages");
     }
     foreach ($packageFiles as $pf) {
         if (substr($pf, 0, 1) != '.') {
             if (pathinfo($pf, PATHINFO_EXTENSION) == 'xml') {
                 $xml = Pagemill_SimpleXmlElement::LoadFile("{$dir}/source/packages/{$pf}");
                 foreach ($xml->updir as $updir) {
                     $updir = trim("{$updir}");
                     $parts = explode("/", $updir);
                     $curDir = '';
                     foreach ($parts as $part) {
                         if ($part) {
                             $curDir .= "/{$part}";
                             if (!file_exists(TYPEF_DIR . $curDir)) {
                                 $ftp->mkdir($curDir);
                                 $ftp->chmod(0777, $curDir);
                             }
                         }
                     }
                 }
             }
         }
     }
     $ftp->close();
     // Update base models if package contained any
     if (file_exists("{$dir}/source/classes/BaseModel")) {
         $modelFiles = scandir("{$dir}/source/classes/BaseModel");
         foreach ($modelFiles as $mf) {
             if (substr($mf, 0, 1) != '.') {
                 $pathinfo = pathinfo($mf);
                 if ($pathinfo['extension'] == 'php') {
                     $cls = "BaseModel_{$pathinfo['filename']}";
                     $mod = new $cls();
                     $src = Dbi_Source::GetModelSource($mod);
                     $src->configureSchema($mod);
                 }
             }
         }
     }
 }
예제 #5
0
파일: Model.php 프로젝트: ssrsfs/blg
 public function __construct()
 {
     $this->source = Dbi_Source::GetModelSource($this);
 }