* @license PHP License
 * @package WB
 * @subpackage Wikipedia
 */
error_reporting( E_ALL | E_STRICT );

$base = realpath( dirname( __FILE__ ) . '/..' );

class MoveSymlink
{
    protected $base;

    public function __construct( $base )
    {
        $this->base = $base;
    }

    public function renamePat()
    {
        $des = $this->base . '/include/pat';
        $list = new DirectoryIterator( $des );
        $src = $this->base . '/lib';

        foreach( $list as $d ) {
            if( $d->isDot() || $d->isDir() ) {
                continue;
            }

            $name = explode( '.', $d->getFilename() );
            $ext = array_pop( $name );
            $php = false;
            if( $ext == 'txt' ) {
                continue;
            }

            if( $ext != 'php' ) {
                continue;
            }

            $name = implode( '.', $name );
            if( $name == 'patErrorManager' ) {
                echo "unlink " . $d->getPath() . '/' . $d->getFilename() . "\n";
                echo "copy " . $src . '/patError/' . $d->getFilename() . " => " .  $des . '/' .  $d->getFilename() . "\n";
                unlink( $d->getPath() . '/' . $d->getFilename() );
                copy( $src . '/patError/' . $d->getFilename(),  $des . '/' .  $d->getFilename() );
                continue;
            }

            if( $name == 'patError' ) {
                echo "unlink " . $d->getPath() . '/' . $d->getFilename() . "\n";
                echo "copy " . $src . '/patError/' . $d->getFilename() . " => " .  $des . '/' .  $d->getFilename() . "\n";
                unlink( $d->getPath() . '/' . $d->getFilename() );
                copy( $src . '/' . $name . '/' . $d->getFilename(),  $des . '/' .  $d->getFilename() );
                continue;
            }

            echo "unlink " . $d->getPath() . '/' . $d->getFilename() . "\n";
            echo "unlink " . $d->getPath() . '/' . $name . "\n";
            unlink( $d->getPath() . '/' . $d->getFilename() );
            unlink( $d->getPath() . '/' . $name );

            // copy file and move folder
            echo "copy " . $src . '/' . $name . '/' . $d->getFilename() . " => " .  $des . '/' .  $d->getFilename() . "\n";
            echo "rename " . $src . '/'. $name . '/' . $name . " => " .  $des . '/' .  $name . "\n";
            copy( $src . '/' . $name . '/' . $d->getFilename(),  $des . '/' .  $d->getFilename() );
            rename( $src . '/'. $name . '/', $des . '/' .  $name );
        }
    }
}

$ms = new MoveSymlink( $base );
$ms->renamePat();

?>